skills/sql-injection-anti-pattern/SKILL.md
Security anti-pattern for SQL Injection vulnerabilities (CWE-89). Use when generating or reviewing code that constructs database queries, builds SQL statements, or handles user input in database operations. Detects string concatenation in queries and recommends parameterized queries.
npx skillsauth add igbuend/grimbard sql-injection-anti-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Severity: Critical
Attackers execute arbitrary SQL commands by manipulating user input. String concatenation in queries (frequently AI-generated from insecure training data) enables database compromise, data exfiltration, authentication bypass, and remote code execution.
The anti-pattern is concatenating user data into SQL statements, allowing attackers to break query structure and inject malicious SQL.
# VULNERABLE: String concatenation creates injection vector.
import sqlite3
def get_user(db_connection, username):
# User input concatenated directly into query.
query = "SELECT * FROM users WHERE username = '" + username + "'"
cursor = db_connection.cursor()
cursor.execute(query)
return cursor.fetchone()
# Attack: username = "admin' OR '1'='1' --"
# Result: "SELECT * FROM users WHERE username = 'admin' OR '1'='1' --'"
# Returns all users, bypassing authentication.
# SECURE: Parameterized queries prevent injection.
import sqlite3
def get_user(db_connection, username):
# Parameters sent separately and escaped by database driver.
# Malicious input cannot alter query logic.
query = "SELECT * FROM users WHERE username = ?"
cursor = db_connection.cursor()
cursor.execute(query, (username,))
return cursor.fetchone()
# Named parameters (preferred for clarity):
# query = "SELECT * FROM users WHERE username = :username"
# cursor.execute(query, {"username": username})
+, ||, concat(), f-strings, template literals) used to build SQL queries.execute(), query(), or raw() that take a single string variable which may contain user input..format(), %s, or ${} within SQL query strings.development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.