Skip to content
ScanAnt

What is SQL injection?

SQL injection is a vulnerability where user input is pasted into a database query as text, so an attacker can change what the query does. It can expose, change or delete data that the application never meant to reveal.

How it works

When code builds a query by joining strings, the database cannot tell your SQL from the user's input. A value such as a quote followed by extra SQL changes the logic, for example turning a login check into one that always succeeds, or adding a UNION that returns another table. Parameterised queries avoid the problem by sending the SQL and the values separately, so the values are never executed.

// Vulnerable: string concatenation
const rows = await db.query(
  "SELECT * FROM users WHERE email = '" + email + "'"
);

// Safe: parameter placeholder
const rows = await db.query(
  "SELECT * FROM users WHERE email = $1", [email]
);

How to tell if your site is affected

  • Anywhere your code builds SQL with string concatenation, template literals or format() using request data.
  • A request parameter containing a single quote returns a database error or a 500 instead of a normal "not found".
  • You use raw query helpers such as $queryRawUnsafe, knex.raw, sequelize.query or DB::raw with unchecked input.
  • Sorting and filtering parameters (column names, ORDER BY) are passed straight into the query. These cannot be parameterised and need an allow-list.

How to fix it

  1. Use parameterised queries or prepared statements everywhere. Never concatenate request data into SQL.

  2. Use your ORM's normal methods. In Prisma prefer $queryRaw with tagged templates over $queryRawUnsafe; in Laravel use query builder bindings rather than DB::raw with variables.

  3. For dynamic column or sort names, map input to a fixed allow-list of known values.

  4. Give the application database user the least privileges it needs: no DROP, no access to other schemas.

  5. In Supabase, use the client's filter methods and row-level security instead of building SQL strings in an Edge Function.

How ScanAnt checks for it

Deep scanCode scan

SQL injection needs probes, so it is not part of the free quick scan. In the deep scan for verified owners, ScanAnt sends harmless markers in GET parameters and looks for database error messages in the response. It does not extract data or submit your forms with test payloads (level-3 rate-limit probes send only a tagged test body). The code scan flags SQL built from strings in an uploaded project. A clean result does not prove that no injectable parameter exists, since POST bodies and logged-in areas are out of reach.

Questions

Is SQL injection still common?

Yes. It sits in the OWASP Top 10 under Injection. Modern frameworks make it rarer, but raw queries, search filters and generated code still introduce it.

Does an ORM prevent SQL injection?

Mostly, when you use its standard methods, because they use parameters. Raw query escape hatches and string-built filters bring the risk back.

Can I stop it by filtering quotes?

No. Blacklists and manual escaping are fragile. Parameterised queries are the reliable fix.

Does NoSQL injection exist too?

Yes. MongoDB and similar stores can be attacked by sending objects such as {"$ne": null} where a plain string was expected. Validate types and never pass request bodies directly into queries.

See if your site is affected

Free for any public site, no signup. Need the verified or deep scan? Choose the level on the scan page.

Choose a scan level →