Injection was first on the OWASP Top 10 in 2010, 2013 and 2017. In 2021 it fell to third, behind Broken Access Control and Cryptographic Failures. The revision also folded cross-site scripting (XSS) into this category. A script injected into a page and a query injected into a database are the same bug: untrusted input interpreted as a command.

OWASP has since published a 2025 edition of the Top 10. This article covers the 2021 edition.

Injection happens when data supplied by a user crosses into a place where it is executed as code. An interpreter, a SQL engine, a shell, an LDAP directory, a browser's HTML parser, receives a string that mixes the developer's intended instructions with the attacker's, and cannot tell them apart. The interpreter does what it always does: it runs what it was given.

SQL injection

Injection: SQL, XSS, and the Untrusted Input ProblemDiagram with these labels, in reading order: ATTACKER; WEB APP; INTERPRETER / DB; mixed string; the safe binding; Untrusted input; ' OR '1'='1; Concatenated into; query / page; Interpreter runs it; SQL / browser /; shell; Data ≠ code; Parameterised query; Rows dumped /; script executes; Data meets code with; no separation.ATTACKERWEB APPINTERPRETER / DBmixed stringthe safe bindingUntrusted input' OR '1'='1Concatenated intoquery / pageInterpreter runs itSQL / browser /shellData ≠ codeParameterised queryRows dumped /script executesData meets code withno separation
Untrusted input crosses into a place where it is executed as code.

The archetype is SQL injection. A query built by concatenating user input lets an attacker rewrite its logic, bypassing a login, dumping a table, or, with stacked queries, altering data. The fix is parameterised queries instead of cleverer filtering, which send the query structure and the data on separate channels so the input can never become part of the command.

Concatenation turns a login into a bypassquery = "SELECT * FROM users WHERE name = '" + input + "'"
input = ' OR '1'='1 → returns every row; authentication defeated

Cross-site scripting

XSS is injection into the browser. Untrusted input is reflected into a page without encoding, and the victim's browser executes it as script, stealing session tokens, rewriting the page, or acting as the user. It comes in three shapes: reflected (payload echoed from the request), stored (payload saved and served to every viewer), and DOM-based (client-side JavaScript writes untrusted data into the page). The defense is contextual output encoding, so data rendered into HTML, attributes, or scripts is always treated as text, never as markup.

Command injection and other interpreters

The same pattern recurs wherever an interpreter meets untrusted input. OS command injection passes user data to a shell that runs it as a command. LDAP, XPath, NoSQL, and template injection are all variations on the theme. The category is broad precisely because the mistake is general: trusting input at the boundary where it becomes executable.

Why it merged with XSS: The 2021 list unified injection and XSS because they share one root cause and one class of fix. Treating them as one keeps the focus on the boundary between data and code.

Preventing it

  • Use parameterised queries and prepared statements for all database access. Never build queries by concatenation.
  • Encode output for its context. HTML-encode, attribute-encode, or JavaScript-encode data at the point it is rendered, and prefer frameworks that do this by default.
  • Avoid calling out to a shell; use safe library APIs. Where a command is unavoidable, pass arguments as a list, never as an interpolated string.
  • Validate input positively. Allow-list expected formats server-side; treat validation as defense in depth, not the primary control.
  • Deploy a Content Security Policy to blunt the impact of any XSS that slips through.
  • Use static analysis and dynamic testing to find injection sinks before attackers do.

Injection has stayed near the top of this list across its revisions because the fix is well understood and the mistake keeps recurring in new code and new interpreters. Every input that reaches an interpreter is a place to get it wrong, which is why knowing where your untrusted data flows is the precondition for keeping it safe.

Primary source. A03:2021 : Injection, OWASP.

Back to the knowledge baseRequest an assessment