Prevent SQL injection attacks using prepared statements, parameterized queries, and input validation. Use when building database-driven applications securely.
Implement comprehensive SQL injection prevention using prepared statements, parameterized queries, ORM best practices, and input validation.
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)
Detailed implementations in the references/ directory:
| Guide | Contents | |---|---| | Node.js with PostgreSQL | Node.js with PostgreSQL | | Python with SQLAlchemy ORM | Python with SQLAlchemy ORM | | Java JDBC with Prepared Statements | Java JDBC with Prepared Statements | | Input Validation & Sanitization | Input Validation & Sanitization |
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/sql-injection-prevention · pinned to the source commit
git clone https://github.com/aj-geddes/useful-ai-prompts.git
cd useful-ai-prompts
git checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills/sql-injection-prevention"
cp -r "skills/sql-injection-prevention" ".claude/skills/sql-injection-prevention"Review the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
Scanner static-checks@0.1.0 · commit 3f5182cfd739. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
References credentials, tokens or secret files that a skill should not need.
Evidence: [redacted]· fingerprint e9cbb0224c4a3d23