secure-sql-usage

A set of rules for code that communicates with SQL databases. It requires parameterized queries, which keep user-provided values separate from SQL commands.

In plain words
What is it for?
Use it when writing or reviewing database code in any language or framework, including generated code.
Why use it?
It reduces the risk of SQL injection, where crafted input changes what a database query does.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/matank001/cursor-security-rules/secure-sql-usage
Clone the repo
git clone --depth 1 https://github.com/matank001/cursor-security-rules
Per session 586 This file is loaded in full into every session.
When invoked 586 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00586 $0.00586
Opus 5 $0.00293 $0.00293
Sonnet 5 $0.00117 $0.00117
Haiku 4.5 $0.00059 $0.00059

Measured yesterday against content hash 86042862605f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

secure-sql-usage scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

secure-sql-usage.mdc · 53 lines

How it starts

The opening of the file, as written. The whole thing — 53 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Secure SQL Usage

These rules apply to all code that interacts with SQL databases, regardless of language or framework, including generated code.

All violations must include a clear explanation of which rule was triggered and why, to help developers understand and fix the issue effectively.
Generated code must not violate these rules. If a rule is violated, a comment must be added explaining the issue and suggesting a correction.

1. Always Use Parameterized Queries and Prepared Statements

  • Rule: Never construct SQL queries by concatenating or interpolating user input directly into the query string. Always use parameterized queries or prepared statements provided by your database library. Prepared statements ensure that user input is treated as data, not executable code, and are the most effective way to prevent SQL injection.
  • Example (unsafe, Python):
    cursor.execute(f"SELECT * FROM users WHERE username = '{username}'")
    
  • Example (safe, Python):
    cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
    
  • Example (unsafe, PHP):
    $query = "SELECT * FROM users WHERE username = '" . $_GET['username'] . "'";
    $result = mysqli_query($conn, $query);
    
  • Example (safe, PHP - using prepared statements):
    $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
    $stmt->bind_param("s", $_GET['username']);
    $stmt->execute();
    $result = $stmt->get_result();
    

2. Validate and Sanitize All Input

  • Rule: All external input used in queries must be validated for type, length, and format. Apply allow-lists where possible.

3. Avoid Dynamic SQL Unless Absolutely Necessary

  • Rule: Do not use dynamic SQL (e.g., building table or column names from user input) unless there is no alternative. If unavoidable, strictly validate and allow-list all dynamic parts.

4. Use Least Privilege Database Accounts

  • Rule: Connect to the database using accounts with the minimum privileges required for the task. Never use admin or superuser accounts for application queries.

Read the full file on GitHub · 53 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 53 lines · 586 tokens per session scan A 86042862605f

Subscribe to this mod's changes

secure-sql-usage is a cursor rule published in the GitHub repository matank001/cursor-security-rules (379 stars, last pushed 1y ago), licensed MIT. It adds 586 tokens to every session, about $0.0029 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.