sql-injection

A security rule for finding SQL injection in Forge apps that use the Forge SQL API, a database interface for storing and querying data. SQL injection happens when untrusted input changes the meaning of a database query.

In plain words
What is it for?
Use it to inspect executeRaw(), prepare(), and migration queries receiving resolver payloads, web-trigger bodies, event data, or Custom UI input.
Why use it?
It identifies queries built by inserting user-controlled values directly into SQL, which can expose or alter stored data.

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/atlassian/forge-skills/sql-injection
Clone the repo
git clone --depth 1 https://github.com/atlassian/forge-skills
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,102 The whole file, excluding the scripts and references it only reads on demand.
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.00012 $0.01102
Opus 5 $0.00006 $0.00551
Sonnet 5 $0.00002 $0.00220
Haiku 4.5 $0.00001 $0.00110

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

Security

Grade A, and why

sql-injection 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.

skills/forge-security-review/assets/security-rules/forge-injection/sql-injection.mdc · 143 lines

How it starts

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

Context

  • Forge SQL API provides sql.executeRaw() and sql.prepare() for database operations. SQL injection occurs when untrusted input is interpolated into query strings.
  • Related CWE: CWE-89 (SQL Injection).
  • Severity: Critical - can lead to data exfiltration, manipulation, and privilege escalation.
  • Reference: Internal VULN Guide to SQL Injection in Forge Apps.

Scope & Signals

  • Dangerous APIs:
    • sql.executeRaw() - Direct query execution (highest risk)
    • sql.prepare() without bindParams() - Prepared statement misuse
    • migrationRunner.enqueue() with dynamic content
  • Sources: Resolver payloads, web trigger bodies, event data, user input from Custom UI.
  • Sinks: Any SQL query construction using string interpolation/concatenation.

Vulnerable Patterns

// CRITICAL - Direct interpolation in executeRaw
const userId = payload.userId;
sql.executeRaw(`SELECT * FROM users WHERE id = ${userId}`);

// CRITICAL - String concatenation
sql.executeRaw("SELECT * FROM users WHERE username = '" + username + "'");

// HIGH - Prepared statement without bindParams
sql.prepare(`SELECT * FROM users WHERE email = '${email}'`).execute();

// HIGH - Template literal in prepare (still vulnerable)
const query = `SELECT * FROM products WHERE category = '${category}'`;
sql.executeRaw(query);

// MEDIUM - Indirect flow through variable
const userQuery = `SELECT * FROM orders WHERE user_id = ${payload.userId}`;
// ... later ...
sql.executeRaw(userQuery);

Secure Patterns

// SECURE - Parameterized query with bindParams
const query = sql.prepare(`SELECT * FROM users WHERE id = $1`);
query.bindParams({ $1: userId });
await query.execute();

// SECURE - Multiple parameters
const query = sql.prepare(
  `SELECT * FROM users WHERE username = $1 AND active = $2`
);
query.bindParams({ $1: username, $2: isActive });
await query.execute();

// SECURE - Named parameters (alternative style)
const query = sql.prepare(
  `SELECT * FROM users WHERE email = :email AND role = :role`
);
query.bindParams({ email: userEmail, role: userRole });
await query.execute();

// SECURE - Input validation + parameterization
if (!/^\d+$/.test(userId)) {
  throw new Error('Invalid user ID format');
}
const query = sql.prepare(`SELECT * FROM users WHERE id = $1`);
query.bindParams({ $1: parseInt(userId, 10) });

Detection Checklist

  • Search for sql.executeRaw with template literals or string concatenation.
  • Find sql.prepare calls without corresponding bindParams().
  • Trace variables used in SQL strings back to untrusted sources.
  • Check migrationRunner.enqueue for dynamic schema/table names.
  • Look for custom "sanitization" functions (often insufficient).

Severity Classification

Severity Pattern
Critical Direct user input in sql.executeRaw()
High sql.prepare() without bindParams()
Medium Indirect flow with some transformations
Low Input validated against strict allowlist

Common Pitfalls

// WRONG - Numeric values still need binding
sql.executeRaw(`SELECT * FROM products WHERE id = ${productId}`);

// WRONG - Custom escaping is insufficient
const safe = input.replace(/'/g, "''");
sql.executeRaw(`SELECT * FROM users WHERE name = '${safe}'`);

// WRONG - toString() doesn't sanitize
sql.executeRaw(`SELECT * FROM logs WHERE date = '${date.toString()}'`);

PoC / Test Leads

  • Inject SQL metacharacters: ' OR '1'='1, '; DROP TABLE users; --
  • Test UNION-based injection: ' UNION SELECT * FROM sensitive_table --
  • Try time-based blind SQLi: ' AND SLEEP(5) --
  • Test in numeric fields: 1 OR 1=1

Remediation Guidance (advisory)

  • Always use sql.prepare() with bindParams() for all queries.
  • Use positional ($1, $2) or named (:param) parameters.
  • Validate input types before use (even with parameterization).
  • For dynamic table/column names, use strict allowlists.
  • Never use string concatenation or interpolation for SQL.

Read the full file on GitHub · 143 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 · 143 lines · 12 tokens per session scan A fabdfd6edf6c

Subscribe to this mod's changes

sql-injection is a cursor rule published in the GitHub repository atlassian/forge-skills (20 stars, last pushed 2d ago), licensed Apache-2.0. It adds 12 tokens to every session and 1,102 once invoked, about $0.0001 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.