CWE-89AI-written & agentic codeSeverity · High

Queries built by joining strings

Code builds SQL by joining user input into the query text. A crafted value can change the query to read, change or delete data the user should never reach.

At a glance

Controls
CWE-89 · A03:2021 Injection
Typical severityHigh
ReferenceCWE-89
OWASP Top 10A03:2021 Injection

What it is

Generated code often builds a query by pasting a value from the request into the SQL text. The database cannot tell the value apart from the query. A value with quotes or SQL words becomes part of the command.

An attacker sends a crafted value that changes what the query does. They can read other users' records, bypass a login check or alter data. AI-assisted attackers can try many payloads per field and read the error messages to adjust quickly.

Where it hides

What a reviewer can look for in the code and in the behaviour, before anyone proves it.

  • Search, filter and sort parameters on list endpoints
  • Report and export features that build dynamic queries
  • Raw query calls inside an ORM, used for complex joins
  • Admin and back-office tools that accept free-text conditions

How MATT tests it

The proof runs against the deployed product, on every release, whoever wrote the code.

  1. 01Read the code for queries built with string joining, formatting or template literals.
  2. 02Sign in with the test login and send a value with a single quote to the matching field, watching for errors or changed results.
  3. 03Send a harmless payload that changes only the logic of a read query, such as an always-true condition, against test data.
The rule, in plain English

Queries must use parameters for every value from a user.

Executable check

as test user: GET /v1/items?search=' OR '1'='1 expect: same results as a literal search for that text expect: no database error in the body scan code: expect no query text built from request values

Every rule MATT holds →

What the fix looks like

  1. 01

    Use parameterised queries or prepared statements for every value.

  2. 02

    Map sort and column names to a fixed allow‑list in code.

  3. 03

    Run the application with a database role that has only the rights it needs.

  4. 04

    Add a static check in CI that fails on query strings built from variables.

A check that was never written is found by proving the deployed behaviour, fixed with the engineer who shipped it, and kept fixed by running the control on every change. What is ExploitOps? →

ExploitOps discovery call

Understand where your security loop breaks.

A call with a MATT co-founder to understand your product and whether an ExploitOps Review is worth doing. If there is a real need, we scope one with the research team.

Let’s understand your priority

What brings you to MATT?

What would you like help with?
01 / 02