Innomerc Learn
English is the default.
Application Security

SQL Injection

See what happens when data changes query structure, then separate the statement from its parameters.

Intermediate6 min explorationReviewed
My learningNot started

Choose your depth. Learn at your own pace.

Simple explanation

Understand it

SQL injection happens when untrusted input is interpreted as part of a database instruction rather than only as data. A search box should provide a search value, not control the structure of the query that the application executes.

In the fictional catalog, the unsafe path builds a query by joining text. The safer path sends a fixed statement and a separate value. The visual represents input symbolically; it does not provide an executable attack against a database.

Technical explanation

Under the hood

Parameterized queries let the database driver distinguish statement structure from bound values. They are the primary defense for values. Dynamic identifiers such as table names or sort directions usually cannot be bound in the same way and need strict allowlisted selection.

Escaping rules are database- and context-dependent and should not replace parameterization. An ORM can still become unsafe when code drops into raw query construction. Stored procedures can also be vulnerable if they construct dynamic SQL unsafely.

Practitioner explanation

Practitioner perspective

Review data flows from request parameters, imported files and stored values into query construction. A value saved earlier can become unsafe when used in a later dynamic query. Test with synthetic data and an explicitly authorized scope.

Use database permissions to reduce impact: the application account should not have unnecessary administrative privileges. Investigate unusual query errors and access patterns, while avoiding logging secrets or entire sensitive queries. Error suppression alone does not remove injection.

See the decision happen

Watch it work

A fictional, simplified model. Select a component to inspect it, or follow the steps in order.

Explore the system

Search input

An untrusted search value reaches the application.

1 / 4
Read every step without animation

Unsafe concatenation

  1. Search input. An untrusted search value reaches the application.
  2. String assembly. The application joins input directly into query text.
  3. Changed structure. Input is interpreted as part of the instruction.
  4. Unexpected access. The query may operate outside the intended search.

The data/instruction boundary was lost.

Parameterized query

  1. Search input. The same untrusted value reaches the application.
  2. Fixed statement. The application prepares a statement with a value placeholder.
  3. Bound value. The driver sends the input as data for that placeholder.
  4. Intended query. The input does not alter the statement structure.

Separate query structure from untrusted values.

Explore deeper: additional experiment
Change an input. Inspect the consequence.

Where does user input go?

Query structure + separate value

The SQL structure is fixed before the value is bound. Syntax characters in a value do not become SQL instructions at this parameter boundary. Dynamic table and column names require separate allowlisting.

A local teaching model with fictional inputs. It does not test a live system.

Attack view

The input in this model changes the intended query structure. The failure occurs before execution, at the boundary where application data becomes database syntax.

Defender view

  • Use parameterized queries for values.
  • Allowlist unavoidable dynamic identifiers and avoid unnecessary raw SQL.
  • Restrict database account privileges and handle errors without exposing internals.

Common mistakes

  • An ORM is not safe when raw SQL is assembled unsafely.
  • Input filtering alone is not a universal SQL injection defense.

Check your understanding

What is the primary defense for user-supplied SQL values?
Active recall: explain this idea in 30 seconds

SQL injection happens when untrusted input is interpreted as part of a database instruction rather than only as data. A search box should provide a search value, not control the structure of the query that the application executes.

Now give an example and name one limitation. Revisit the explanation if you get stuck.

Primary sources

Original explanations informed by these specifications and official resources. Source versions and lesson review are separate from product updates.

Content reviewed 2026-09-10. Read the editorial policy.

What comes next?

Web and application security

Back to topic