Skip to main content

A05:2025 — Injection

OWASP · Top 10:2025 · Reading time: ~14 min

At a Glance​

Rank#5 in 2025 (#3 in 2021; #1 in 2017 — and #1 for most of the list's history)
Mapped CWEs38
Example CWEsCWE-89 SQL Injection, CWE-79 Cross-site Scripting, CWE-78 OS Command Injection, CWE-77 Command Injection, CWE-90 LDAP Injection, CWE-917 Expression Language Injection, CWE-1336 Template Injection, CWE-94 Code Injection
NoteXSS has been part of this category since 2021

In Plain English​

Every application talks to interpreters: a database speaks SQL, the operating system speaks shell commands, the browser speaks HTML and JavaScript, a template engine speaks its own expression language.

Injection happens when the application builds a message for one of those interpreters by gluing user input into code. If the input contains the interpreter's own syntax, the interpreter can't tell where the developer's code ends and the attacker's begins.

Developer intends: SELECT * FROM users WHERE name = '<DATA>'
User supplies: x' OR '1'='1
Interpreter sees: SELECT * FROM users WHERE name = 'x' OR '1'='1'
└────────────┘
now part of the query's logic

It dropped to #5 not because it's harmless, but because modern frameworks (parameterised ORMs, auto-escaping templates) prevent it by default. When it does occur, the impact is still often catastrophic: full database dumps, account takeover, or remote code execution.


The Injection Family​

TypeInterpreterTypical impact
SQL injectionRelational databaseRead/modify/delete data, bypass login, sometimes code execution
NoSQL injectionMongoDB and similarLogin bypass, data extraction via operator injection
OS command injectionSystem shellFull server compromise
LDAP / XPath injectionDirectory or XML query enginesAuthentication bypass, data disclosure
Template injection (SSTI)Server-side template engineOften remote code execution
Expression language injectionFramework EL/OGNL/SpELRemote code execution
Cross-site scripting (XSS)The victim's browserSession theft, actions as the victim, data theft
Header/CRLF injectionHTTP protocolResponse splitting, cache poisoning, log forgery
Freshers' takeaway

Learn the pattern once and you've learnt the whole category: code and data mixed in one string, handed to an interpreter. The fix is always to keep them separate — parameters for SQL, argument arrays for commands, context-aware encoding for HTML. "Filtering bad characters" is never the main fix.


Vulnerable vs. Fixed Code​

Vulnerable — string concatenation:

const q = `SELECT * FROM products WHERE category = '${req.query.cat}'`;
const rows = await db.query(q);

Fixed — parameterised query; the driver sends data separately from the SQL:

const rows = await db.query(
'SELECT * FROM products WHERE category = $1',
[req.query.cat]
);

Identifiers (table/column names, ORDER BY fields) can't be parameterised — map user choices to an allowlist instead:

const SORTABLE = { price: 'price', name: 'name', newest: 'created_at' };
const column = SORTABLE[req.query.sort] ?? 'name';

Real-World Incidents​

  • MOVEit Transfer (CVE-2023-34362, 2023) — A SQL injection in a widely used managed file-transfer product was exploited at scale by a ransomware group, leading to data theft from a very large number of organisations worldwide.
  • Heartland Payment Systems (2008) — SQL injection was the initial entry point in one of the largest payment-card breaches of its era.
  • Equifax (2017) — The initial exploit targeted an unpatched Apache Struts vulnerability (CVE-2017-5638) that allowed command execution through an injected expression in an HTTP header — an injection flaw delivered through a vulnerable component.

How to Test for It​

  • Map every input: URL and query parameters, form fields, JSON/XML bodies, headers (User-Agent, Referer, X-Forwarded-For), cookies, file names and file contents.
  • Send interpreter-specific "breaking" characters (', ", ;, `, $(, {{, <) and look for errors or behaviour changes.
  • Use boolean pairs (AND 1=1 vs AND 1=2) and compare response length/content for blind SQLi.
  • Use time delays (SLEEP, pg_sleep, WAITFOR DELAY, sleep 5) where nothing is reflected.
  • Try polyglot template probes such as ${7*7}{{7*7}} and look for 49.
  • For XSS, check where the input is reflected (HTML body, attribute, script, URL) and test with a payload suited to that context.
  • Use out-of-band callbacks (DNS/HTTP to a listener you control) for blind command injection, SSRF-style SQLi and blind XSS.
  • Confirm with tools only after manual analysis: sqlmap for SQLi, commix for command injection, scanners for broad coverage.
  • In code review, search for string-built queries, exec/eval, os.system, shell=True, innerHTML, dangerouslySetInnerHTML, v-html, and raw ORM queries.

How to Prevent It​

PracticeWhy
Parameterised queries / prepared statementsThe query's structure is fixed before data is attached.
Use safe APIs that don't invoke an interpreterLibrary functions instead of shell commands; ORM methods instead of raw SQL.
Allowlist validation for structureEnum-like inputs (sort order, column names, file types) should only ever be one of a known set.
Schema validation on request bodiesStops type confusion like NoSQL operator injection.
Context-aware output encodingEncode for HTML body, attribute, JavaScript or URL as appropriate; use auto-escaping templates.
Content Security PolicyLimits damage if an XSS slips through.
Least privilegeA database account that can't DROP tables or read other schemas limits blast radius.
SAST/DAST in CIStatic and dynamic scanners catch the most common patterns early.
Escaping is a last resort

Manually escaping special characters is fragile — every interpreter, version and context has its own rules. Use it only when there is truly no parameterised or structured API available, and use a well-tested library to do it.


Pro Notes​

  • Second-order injection. Input stored safely today can be injected tomorrow when another component reads it back and concatenates it into a query. Every use of data must be safe, not just the first write.
  • ORM escape hatches. raw(), extra(), literal(), sequelize.query() and string-interpolated where clauses reintroduce SQLi inside "safe" frameworks.
  • WAFs buy time, not safety. A web application firewall is useful for virtual patching but is regularly bypassed through encoding tricks, alternative syntax and parameter pollution.
  • Prompt injection in LLM-powered applications follows the same pattern — instructions and data mixed in one channel — but has no complete equivalent of "parameterisation" yet. OWASP tracks it separately in its Top 10 for LLM Applications.

Key Takeaways​

  • Injection = user data mixed into code for an interpreter (SQL, shell, browser, template engine).
  • XSS is part of this category.
  • The fix is structural: parameters, safe APIs, argument arrays, auto-escaping and schema validation.
  • It's less common than it used to be, but still one of the highest-impact bug classes when it appears.

Go deeper: SQL & NoSQL Injection · Command & Code Injection · Template Injection · XSS


Next​

A06:2025 — Insecure Design