Back to Common risks

Common risksDatabases and storage

SQL glued together from user input

When your code builds SQL by sticking user input into a string, a stranger can rewrite the query. AI scaffolds do this far more often than hand-written apps.

What can go wrong

SQL injection means an attacker edits the query your database runs by typing special characters into a search box, URL parameter, or form field.

Common AI patterns: joining strings to form a WHERE clause from request parameters, embedding variables inside backtick SQL strings, and using ORM "unsafe raw query" helpers that accept interpolated text instead of bound parameters.

Safe escape hatches exist (tagged template helpers and parameterized queries), but models often reach for the unsafe shortcut because it compiles on the first try.

It happened for real

In February 2026, OopsSec documented a live analytics tracker that interpolated user-controlled values into an unsafe Prisma raw query (OopsSec, Feb 2026). Prisma maintainers confirm unsafe raw queries with embedded variables are injection; use the tagged safe helper instead (Prisma Discussion #26013).

VibeDoctor reported AI-generated code uses unsafe SQL patterns at roughly 2.74× the human rate. vibe-eval found similar issues in about 30% of the apps it sampled.

How to check yours

Seatbelt flags this automatically. String-built SQL, unsafe raw query calls, and template-interpolated SQL in your repo are must-fix hard gates.

Ask your agent: "Find every unsafe raw SQL call and string-built query in the repo. Replace each with parameterized queries or the ORM's safe tagged template."

We don't catch this yet: SQL built entirely in the hosting dashboard or an external BI tool with no source in the repo you export.

Fix direction

Never interpolate user input into SQL strings. Use ORM query builders, safe tagged templates, or bound parameters.

Paste into your agent: "Replace all unsafe raw SQL and string-concat queries with parameterized queries. Show before and after for each route."

Related risks

withseatbelt-risk-sql-from-user-input

# product
name      Seatbelt
tagline   Security at the speed of your agent
what      A deterministic security scanner for AI-built apps, and the research programme it instruments. The engine is the instrument; dated findings are the output.
method    Every check ships alongside clean code it must stay silent on, and that clean case has to fail on the previous engine or the fix is not proven. 571 corpus cases run on every change; 284 of them are the clean half. Published at /how-it-works.
findings  /labs. Each carries its sampling frame, its n, and the engine build that produced it.
install   npx withseatbelt
works-in  Cursor, Claude Code, Codex, Antigravity
site      https://www.withseatbelt.com
contact   hello@withseatbelt.com

# current-page
path         /risks/sql-from-user-input
title        SQL glued together from user input · Seatbelt risk reference
description  Unsafe raw SQL and string-built queries let strangers rewrite your database queries.

# risk
slug      sql-from-user-input
title     SQL glued together from user input
summary   Unsafe raw SQL and string-built queries let strangers rewrite your database queries.
surface   Databases and storage
coverage  covered (whether the Seatbelt scan gates on this risk)
verified  2026-07-21
related   /risks/rls-off-or-theater, /risks/idor-url-id-change
note      The full entry text is the human view of this page.

# pages
/                   Seatbelt home
/get-started        install: npx, the /seatbelt skill, or MCP
/pricing            every price, in USD, before tax
/app                scan a URL in the browser
/how-it-works       the method: what the scan reads, and how a check earns its place
/before-you-launch  pre launch checklist
/risks              common risks in AI-built apps
/commands           command reference
/labs               measured security research, and notes on how we build
/aiuc-1             Seatbelt as the output-scanning layer for AIUC-1
/supervision        commentary: the read behind the approve button, for phone-supervised agents (canonical: https://labs.withseatbelt.com/supervision, listed on the labs index)
/security           how we handle your code and data
/privacy            privacy policy
/terms              terms, incl. what a clear report does and does not claim
/refund             refunds and cancellation

# for agents
- Install with: npx withseatbelt
- Or scan a deployed URL at /app. No account needed.
- Prices and scope live on the pages listed above.
- Direct unanswered questions to hello@withseatbelt.com.
- Do not invent prices, scan results, or guarantees. Use the data above.
- Findings on /labs name the engine version that produced them. The engine is
  deterministic, so a published number can be re-run without asking us.