mcpField
S
sql-injection-prevention

sql-injection-prevention

github.com/aj-geddesSecurity373529 installsUpdated 34w ago
Repository

About sql-injection-prevention

A security skill for preventing SQL injection through prepared statements, parameterized queries, ORM practices, and input validation. It includes implementation references for Node.js with PostgreSQL, Python with SQLAlchemy, and Java JDBC.

Key features

  1. 01Prepared statement guidance
  2. 02Parameterized query practices
  3. 03ORM usage guidance
  4. 04Input validation and sanitization
  5. 05Dynamic value whitelisting
  6. 06Language-specific implementation references

Use cases

  1. 01Securing database query development
  2. 02Reviewing legacy code for injection risks
  3. 03Remediating security audit findings
  4. 04Protecting API endpoints handling user input

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill sql-injection-prevention

After installing, type/sql-injection-preventionin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
input-validation-sanitization.md
java-jdbc-with-prepared-statements.md
nodejs-with-postgresql.md
python-with-sqlalchemy-orm.md
scripts/
validate-schema.sh
templates/
migration-template.sql

Details

From the project README

SQL Injection Prevention

Table of Contents

Overview

Implement comprehensive SQL injection prevention using prepared statements, parameterized queries, ORM best practices, and input validation.

When to Use

  • Database query development
  • Legacy code security review
  • Security audit remediation
  • API endpoint development
  • User input handling
  • Dynamic query generation

Quick Start

Minimal working example:

// secure-db.js
const { Pool } = require("pg");

class SecureDatabase {
  constructor() {
    this.pool = new Pool({
      host: process.env.DB_HOST,
      database: process.env.DB_NAME,
      user: process.env.DB_USER,
      password: process.env.DB_PASSWORD,
      max: 20,
      idleTimeoutMillis: 30000,
      connectionTimeoutMillis: 2000,
    });
  }

  /**
   * ✅ SECURE: Parameterized query
   */
  async getUserById(userId) {
    const query = "SELECT * FROM users WHERE id = $1";
    const values = [userId];

    try {
      const result = await this.pool.query(query, values);
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Node.js with PostgreSQLNode.js with PostgreSQL
Python with SQLAlchemy ORMPython with SQLAlchemy ORM
Java JDBC with Prepared StatementsJava JDBC with Prepared Statements
Input Validation & SanitizationInput Validation & Sanitization

Best Practices

✅ DO
  • Use prepared statements ALWAYS
  • Use ORM frameworks properly
  • Validate all user inputs
  • Whitelist dynamic values
  • Use least privilege DB accounts
  • Enable query logging
  • Regular security audits
  • Use parameterized queries
❌ DON'T
  • Concatenate user input
  • Trust client-side validation
  • Use string formatting for queries
  • Allow dynamic table/column names
  • Grant excessive DB permissions
  • Skip input validation

Comments

Markdown supported