Use this when untrusted input reaches interpreters (OWASP A03).
Injection
1. Injection: SQL, NoSQL, OS command, LDAP, XSS.
2. Parameterise, encode, validate.
3. Safe APIs.
4. Least privilege.
5. Test continuously.
untrusted input → safe API → no interpretation as code
Context & applicabilityCommon mistakes · platform/version boundaries
- Blacklisting characters instead of using safe APIs.
- Validating on the client only.
- Trusting data from internal services or databases (second-order injection).
- Logging raw input that later gets rendered in an admin panel (stored XSS).
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Use parameterized queries.
- Encode output for its context.
- Validate input.
- SAST findings for injection — code issues
sqlmap/ZAP (authorised)— dynamic tests- Parameterised APIs used — prevention
ReferenceWhy it matters1 section · depth on demand
Defences by type
| Injection | Defence |
|---|---|
| SQL | Parameterised queries / ORM |
| OS command | No shell; argument lists; allowlists |
| LDAP | Escape filter values; parameterised APIs |
| XSS | Output encoding, CSP |
| Template (SSTI) | Never render user input as a template |
General rule: keep data and code separate, validate input against allowlists, and run with least privilege.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Injection happens when untrusted input is interpreted as part of a command or query: SQL, NoSQL, OS commands, LDAP, XPath, template engines, or expression languages. The attacker's data changes what the application executes.
| Injection type | Primary defence |
|---|---|
| SQL | Parameterised queries / ORM |
| OS command | Avoid shells; argument lists; allow-list validation |
| LDAP | Escape special characters, parameterised filters |
| NoSQL | Typed queries, reject operator objects in input |
| Template (SSTI) | Never render user input as templates; sandboxed engines |
| Header/log injection | Encode CR/LF and control characters |
Cross-site scripting is also an injection (into HTML/JavaScript). Common principle: keep data and code separate, validate input against allow-lists, and use safe APIs that do the separation for you.
Injection types
| Type | Sink | Defence |
|---|---|---|
| SQL | Database queries | Parameterised queries |
| OS command | Shell | Avoid shell, argument arrays |
| LDAP | Directory filters | Escape filter characters |
| NoSQL | MongoDB operators | Reject objects where strings are expected ($ne) |
| Template (SSTI) | Template engines | Never render user input as a template |
| XSS | Browser | Context-aware output encoding |
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in OWASP → Injection. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%