The Complete Production SOP: How to Deploy and Run SQL Injection Defense & Parameterized Statements in Autonomous AI Agents
Step-by-step SOP to install & run SQL Injection Defense & Parameterized Statements in Codex, Claude Code, & Cursor. Master parameterized query automation safely.
Technical Overview & Architectural Context
Autonomous coding agents frequently default to string interpolation or template literal formatting (`SELECT * FROM users WHERE email = '${email}'`) when tasked with building fast data-access helpers, prototyping APIs, or refactoring query layers. Without strict procedural governance, language models misinterpret convenience for correctness, assuming internal or sanitised strings pose zero exploit risk. Furthermore, agents often misconfigure complex query constructs like `LIKE %...%` clauses, pagination boundaries (`LIMIT/OFFSET`), and dynamic `IN (?, ?)` clauses, inadvertently concatenating variable inputs into the SQL AST. The `sqli-defense-parameterized-queries` skill imposes deterministic security constraints directly into the agent's reasoning loop across Codex, Claude Code, Cursor, and Windsurf. By enforcing zero-tolerance policies on raw string concatenation, standardizing positional (`$1`, `?`) and named (`:param`) parameters across major ORMs/drivers (e.g., `pg`, `mysql2`, `psycopg3`, `database/sql`), and mandating pre-execution static audits, this skill prevents SQL injection vulnerabilities before code touches revision control.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into your agent runtime.
Agent runtimes such as Claude Code and Codex Desktop discover operational skills by indexing `.agents/skills/` or `.claude/skills/` within the repository root or the user home directory. Placing the verified SKILL.md specification ensures that any agent parsing workspace instructions reads the YAML frontmatter triggers and adopts the SQL parameterization rules.
mkdir -p .agents/skills/sqli-defense-parameterized-queries && curl -fsSL https://askills.dev/api/skills/sqli-defense-parameterized-queries/raw -o .agents/skills/sqli-defense-parameterized-queries/SKILL.md---
name: "sqli-defense-parameterized-queries"
description: "Eliminate SQL injection vulnerabilities using parameterized prepared statements."
metadata:
author: "OWASP"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "prevent sql injection"
- "use parameterized query"
- "fix dynamic sql string concatenation"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Place the SKILL.md inside `.agents/skills/` at the repository root rather than global home to preserve deterministic behavior across team members without inflating base prompt tokens.
Ensure `shell_exec: false` and `net_access: false` remain unmodified. This skill audits and refactors code syntactically; granting shell or network execution creates an unnecessary security attack surface.
Configuring AST Linting & Query Auditing Hooks
Ensure driver libraries and AST-based SQL security linters are present in the project tree.
To allow the agent to self-verify parameterized queries, equip the repository with AST security checkers. For TypeScript/Node.js, install `eslint-plugin-security` or `eslint-plugin-sql`; for Python, ensure `bandit` is configured in `pyproject.toml`. The agent will invoke these tools to validate that no dynamic expressions escape parameter boundaries.
npm install --save-dev eslint-plugin-sql eslint-plugin-security || pip install bandit flake8Configure `.eslintrc.json` or `pyproject.toml` with strict rules (e.g., `sql/no-unsafe-query: error`) so the agent automatically treats string concatenation in DB calls as fatal build errors.
Never hardcode database credentials or connection strings in `.env` files exposed to agent context windows. Use `.env.example` templates with dummy secrets.
Intent Matching & Trigger Invocation
Verify deterministic skill activation using tested natural language prompts and clear scope triggers.
Initiate your agent task using verbs and phrases mapped directly to the skill's frontmatter trigger list (e.g., 'prevent sql injection', 'fix dynamic sql string concatenation', 'use parameterized query'). When the prompt matches these semantic hooks, Claude Code or Codex binds the parameterized query SOP prior to modifying files.
claude 'Audit src/db/users.ts to prevent sql injection and fix dynamic sql string concatenation using parameterized queries.'Prefix the prompt with the specific file scope and target DB engine (e.g., PostgreSQL `$1` vs MySQL `?`) to prevent the agent from cycling through unnecessary driver syntax variations.
Avoid ambiguous instructions like 'make this query safer'. Generic phrasing may cause the agent to implement custom regex sanitization instead of canonical prepared statements.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks and run static analysis before committing changes.
The skill mandates that the agent verify all file modifications using local linters, unit tests, and static analysis. It checks that user variables inside search strings, sorting columns, and filtering clauses are properly passed as parameter arrays or validated against strict whitelists.
npx eslint src/db/ --rule 'sql/no-unsafe-query: error' && npm testInspect the git diff using `git diff -U1` to verify that LIKE patterns handle wildcards via parameter concatenation (e.g., `query, ['%' + term + '%']`) rather than SQL string concatenation.
Ensure that dynamic `ORDER BY` and column identifiers are validated against an allowlist array; prepared statement parameters cannot parameterize table or column names.
Real-World Scenario: Refactoring an Vulnerable Express/PostgreSQL Authentication and Search Service
“Audit and refactor `src/services/userService.ts`. Prevent sql injection, fix dynamic sql string concatenation, and use parameterized queries for user lookup and search endpoints.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent replaced string variables with `$1` and `$2` but left an unparameterized fragment or mismatched placeholder indexing in the SQL statement.
// Ensure SQL placeholders match parameter array length exactly:
// Before: client.query('SELECT * FROM users WHERE id = $1 AND active = true', [id, active]);
// Fix:
const query = 'SELECT * FROM users WHERE id = $1 AND active = $2';
const values = [id, active];
await client.query(query, values);Root Cause: The agent attempted to use prepared statement parameters for table or column names (`SELECT $1 FROM users`), which relational database engines do not permit in query plans.
// Enforce strict identifier allowlisting instead of query parameterization for identifiers:
const ALLOWED_FIELDS = new Map([['name', 'user_name'], ['email', 'user_email']]);
const targetCol = ALLOWED_FIELDS.get(userInputField);
if (!targetCol) throw new BadRequestError('Invalid sort field');
const query = `SELECT ${targetCol} FROM users WHERE tenant_id = $1`;
await db.query(query, [tenantId]);Frequently Asked Questions (SQL Injection Defense & Parameterized Statements SOP)
Q:Can I use SQL Injection Defense & Parameterized Statements across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. Storing the skill in `.agents/skills/sqli-defense-parameterized-queries/SKILL.md` allows Codex, Claude Code, Cursor, and Windsurf to automatically read triggers, permissions, and validation gates uniformly.
Q:How does SQL Injection Defense & Parameterized Statements prevent context window overflow during long agent sessions?
By defining modular SOP rules (parameter placeholders, LIKE wildcard handling, identifier allowlists) inside a compact frontmatter schema, the agent accesses precise, deterministic guidelines without loading bloated security documentation or repetitive sample repositories into the prompt context.
Q:Does this skill require escalated root or container permissions?
No. The skill runs with a verified 98/100 security score. It requires only workspace-level read and write file permissions (`fs_read: true`, `fs_write: workspace`) and strictly blocks shell execution and arbitrary network calls (`shell_exec: false`, `net_access: false`).
Ready to equip your autonomous agent with SQL Injection Defense & Parameterized Statements?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.