Timedora

Injection: Keeping Data Separate from Instructions

Learn how injection risks arise when untrusted input changes instructions, and how to review and defend the boundary where an interpreter receives that input.

Find the , Protect the Boundary

Trace the input to its

Injection occurs when an application combines untrusted input with a command or structured document so that the input changes its meaning. To recognize the risk, follow the input to the component that interprets it—not just to the form or API where it entered. Input may also come from files, cookies, or other systems.

For example, a product-search feature may intend to use a supplied term only as a product name. If the application joins that input into SQL query text, the database may interpret part of it as SQL syntax instead of as a value. That boundary points to the relevant defense: use a parameterized query to keep query structure separate from values. If the application also chooses a table name or sort option dynamically, map those structural choices to a strict allowlist; parameters generally represent values, not table names or SQL keywords.

Match the defense to the interpreter
RiskInterpreterSafe construction
SQL injectionDatabaseParameterized query; allowlist dynamic identifiers or sort choices
Command injectionOperating-system command processor or launched programPrefer a built-in API; if needed, use a fixed executable, separate arguments, and validate each argument
Cross-site scripting (XSS)BrowserContext-appropriate encoding and safe DOM APIs
LDAP injectionDirectory serviceSafe query interface or encoder for the exact context
Injection risks and defenses differ according to the interpreter receiving the input.

Investigate clues; protect the boundary

Review how input is constructed at each boundary: database queries, operating-system commands, browser rendering and DOM updates, and directory filters or names. String concatenation at these boundaries is a reason to examine the construction. Unexpected output, errors, unusual child processes, file or network activity, broad directory results, or unexpected rendered markup can also be clues. But clues are not proof of exploitation, and their absence does not prove a system is safe. Some behavior may be legitimate; DOM-based XSS, for example, may occur entirely in the browser and not appear in server-side logs.

Use an API designed for the relevant to keep data separate from instructions. Add complementary controls: validate values and structural choices, encode output for its destination context, limit application privileges, monitor relevant activity, and test security. These controls do not replace safe construction. Generic character filtering or a firewall alone does not preserve the boundary. Also account for the specific target: separating command arguments helps prevent shell interpretation, but does not by itself make unsafe options or arguments safe; LDAP filters and distinguished names require different escaping rules.

  • : The difference between input treated as a value and input treated as part of an instruction.