Input and injection
Keep data and code apart. Untrusted input must never become part of a query, a page, a shell command, a template, a file or a header.
- Required 7
- Recommended 4
Required
Use parameterised queries
APS-2Send every database query with placeholders, and pass user input as separate values. Never build a query by joining strings.
Keep query operators out of document database input
APS-97Where a document database query expects a plain value, accept only that value. Reject request objects with keys that start with
$, and never pass input to$whereor server-side JavaScript.Escape everything you show
APS-3Escape untrusted text for the place it lands in a page, and back it up with a strict Content Security Policy.
Never pass input to a shell
APS-4Run other programs without a shell, with input as separate arguments. Better still, use a library instead of a program.
Keep input out of templates
APS-5Pass user input to a template as data. Never use it as the template itself.
Turn off external entities in XML
APS-7When the app parses XML, turn off external entities and document types in the parser, or accept JSON instead.
Never rebuild objects from untrusted data
APS-8Read untrusted data only as plain data, such as JSON. Never use formats that can rebuild code objects.
Recommended
Strip line breaks from headers and logs
APS-6Remove or reject line breaks in any input that goes into a header, a redirect, an email header or a log line.
Block prototype pollution
APS-9In JavaScript, never merge or copy untrusted objects in a way that lets keys such as
__proto__change every object in the app.Escape input in directory queries
APS-98Escape every value placed in an LDAP search filter or distinguished name with the library's escape function for that part. Never join raw input into a filter.
Neutralise formulas in spreadsheet exports
APS-99In every CSV or spreadsheet export, quote each field as RFC 4180 says. Put a single quote before any value that starts with
=,+,-,@, a tab, a carriage return or a line feed. Treat the full-width signs=,+,-and@the same way.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/application-security/input-and-injection">Agent Wranglers application security playbook</a>. In code you write, add a comment next to it with the same link.