---
name: detecting-sql-injection-vulnerabilities
description: 'Detect and analyze SQL injection vulnerabilities in application code and database queries.

  Use when you need to scan code for SQL injection risks, review query construction, validate input sanitization, or implement secure query patterns.

  Trigger with phrases like "detect SQL injection", "scan for SQLi vulnerabilities", "review database queries", or "check SQL security".'
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(code-scan:*), Bash(security-test:*)
version: 1.32.0
author: Jeremy Longshore <jeremy@intentsolutions.io>
license: MIT
tags:
  - security
  - database
  - detecting-sql
compatibility: Designed for Claude Code
title: detecting-sql-injection-vulnerabilities
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities
last_updated: 2026-10-23T06:01:00.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [assets/README.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/assets/README.md), [assets/sqli_payloads.json](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/assets/sqli_payloads.json), [references/critical-findings.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/critical-findings.md), [references/errors.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/errors.md), [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/implementation.md), [references/README.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/README.md), [scripts/README.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/scripts/README.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/detecting-sql-injection-vulnerabilities`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/detecting-sql-injection-vulnerabilities`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/detecting-sql-injection-vulnerabilities --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/detecting-sql-injection-vulnerabilities --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Detecting SQL Injection Vulnerabilities

## Overview

Scan application source code for SQL injection vulnerabilities (CWE-89, OWASP A03:2021) by tracing user input from entry points through data flows into database query construction. Detect string concatenation, format string interpolation, and inadequate parameterization across raw SQL, ORM raw query methods, stored procedure calls, and dynamic query builders.

## Prerequisites

- Application source code accessible in `${CLAUDE_SKILL_DIR}/`
- Database query files, ORM models, and repository/DAO layers available
- Framework and language identified (Django, Rails, Express, Spring, Laravel, ASP.NET, Go, etc.)
- Database type known (MySQL, PostgreSQL, SQLite, MSSQL, Oracle) for syntax-specific detection
- Write permissions for reports in `${CLAUDE_SKILL_DIR}/security-reports/`

## Instructions

1. **Discover database interaction code**: search for SQL keywords (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, `EXEC`) and ORM raw query methods (`raw()`, `execute()`, `createNativeQuery()`, `$wpdb->query()`) across all source files.
2. **Identify input surfaces**: map all user-controllable data entry points -- HTTP parameters, request bodies, URL path segments, headers, cookies, file uploads, and WebSocket messages.
3. **Trace data flows**: follow each input surface through the code to determine whether user data reaches a SQL query. Flag any path where input is not passed through parameterized query binding.
4. **Detect vulnerable patterns**:
   - String concatenation: `"SELECT * FROM users WHERE id=" + userId`
   - f-string/format interpolation: Python f-strings embedding variables directly into SQL strings
   - Template literals: `` `SELECT * FROM users WHERE id=${req.params.id}` ``
   - ORM raw queries without bindings: `Model.objects.raw("SELECT * FROM t WHERE x='" + val + "'")`
5. **Classify each finding**: assign CVSS 3.1 score, identify attack type (classic injection, blind boolean/time-based, UNION-based exfiltration, second-order/stored injection), and document exploitability (authentication required, network access).
6. **Assess impact per finding**: determine data exposure scope (authentication bypass, data exfiltration, data modification, OS command execution via `xp_cmdshell` or `LOAD_FILE()`).
7. **Generate remediation code**: provide parameterized equivalents for each vulnerable query. Use framework-idiomatic patterns -- `%s` placeholders for Python DB-API, `?` for Node.js, `$1` for PostgreSQL, named parameters for Spring JPA.
8. **Recommend defense-in-depth measures**: input validation (allowlists over denylists), stored procedures with parameterized calls, least-privilege database accounts, WAF rules, and ORM-only data access policies.
9. **Produce the vulnerability report** at `${CLAUDE_SKILL_DIR}/security-reports/sqli-scan-YYYYMMDD.md` with per-finding severity, CWE-89 mapping, file path and line number, vulnerable code snippet, attack vector demonstration, and remediated code.

See [`references/implementation.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/implementation.md) for the detection pattern library. See [`references/critical-findings.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/critical-findings.md) for example vulnerability write-ups with attack demonstrations.

## Output

- **Vulnerability Report**: `${CLAUDE_SKILL_DIR}/security-reports/sqli-scan-YYYYMMDD.md` with all findings classified by severity
- **Finding Details**: per-finding file path, line number, vulnerable code, attack vector, CVSS score, and remediation code
- **Remediation Summary**: parameterized query replacements grouped by language/framework
- **Defense Recommendations**: input validation rules, database privilege changes, and WAF configuration

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| Unknown ORM or database framework | Custom or uncommon data access library | Apply generic SQL injection pattern detection; note limited framework-specific guidance |
| Cannot analyze compiled/minified code | Production bundles or bytecode instead of source | Request unminified source; document reduced detection accuracy |
| False positive on sanitized input | Proper sanitization exists but not recognized | Trace sanitization implementation manually; whitelist verified-safe patterns |
| Complex dynamic query builder logic | Multi-step query construction across modules | Trace full data flow manually; flag for manual security review |
| Cannot analyze stored procedure definitions | SQL source files not available in `${CLAUDE_SKILL_DIR}/` | Request `.sql` files or database schema exports; focus on application-layer code |

## Examples

- "Scan the codebase for SQL injection risks in dynamic query construction, focusing on controllers and API handlers."
- "Review these query snippets and propose parameterized equivalents with unit tests validating the fix."
- "Detect second-order SQL injection in the user profile update flow where stored data is later used in admin queries."

## Resources

- OWASP SQL Injection Prevention Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
- CWE-89 Improper Neutralization of SQL Syntax: https://cwe.mitre.org/data/definitions/89.html
- OWASP A03:2021 Injection: https://owasp.org/Top10/A03_2021-Injection/
- CAPEC-66 SQL Injection: https://capec.mitre.org/data/definitions/66.html
- [`references/critical-findings.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/critical-findings.md) -- example vulnerability write-ups with attack vectors
- [`references/errors.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/errors.md) -- full error handling reference
- [`references/examples.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/detecting-sql-injection-vulnerabilities/references/examples.md) -- additional usage examples
- https://intentsolutions.io
