Senior · Core path · 6 chapters
Insecure output handling downstream
Model output rendered as HTML (XSS), interpolated into SQL or a shell, used as a file path or a redirect
Model output becomes a security vulnerability when ordinary application code gives it authority over interpreters, files, queries, or navigation.
Read these first
What you will know
Show model output causing XSS in a naive renderer
A browser executes attacker-controlled markup when text is inserted into an HTML context without the correct escaping or sanitization policy.
Trace model output from generation to a downstream sink and mark each trust-boundary crossing
The dangerous assumption is usually introduced by a serializer, template, query builder, or tool wrapper rather than by the model call itself.
Patch HTML, SQL, shell, path, and redirect sinks with context-appropriate controls, then verify with malicious fixtures
Escaping is context-specific: parameterize queries, avoid shell interpretation, constrain canonical paths, and allowlist redirect destinations instead of applying one generic sanitizer.
Reproduce a path traversal using a model-chosen filename, then block it with canonicalization and an allowed-root check
Checking the raw string misses encoded separators, dot segments, symlinks, and alternate path representations.
Run the downstream API with adversarial model outputs and verify schema validation, authorization, and least privilege reject unsafe requests
A valid-looking tool call can still target another tenant, request excessive scope, or exploit a parser unless policy is enforced outside the model.
Chapters
- 1
Insecure output handling
Insecure output handling is what you have when application code hands a model's words to something that acts on them. Teams that scrub every field at the edge conclude they are covered, and the model's answer is a new string created after that scrubbing ran, arriving at sinks the original input never touched. Rendering it with innerHTML in a support console means an injected ticket can execute script inside a staff session, with an agent's authority over every account the console reaches.
- 2
Tracing output to its sinks
Tracing a model response from generation to every place it takes effect, and marking each trust-boundary crossing on the way. the boundary crossing is rarely at the API client. It is a template that inserts the string into markup, a query builder that concatenates a fragment, a tool wrapper that formats an argument into a command — call sites that read as formatting and behave as interpretation.
- 3
Escaping by destination grammar
One sanitiser at the boundary cannot serve an HTML view, a SQL query, a shell command, a filename and a redirect, because each destination parses differently: contextual encoding, bound parameters, an argument array, canonicalisation, an allowlist. The case worth dwelling on is a model-composed WHERE clause, which is structure rather than values and therefore cannot be parameterised at all.
- 4
Path traversal and canonicalisation
Rejecting names that contain '..' or start with a slash validates a string while the operating system decides the outcome, and percent-encoded separators, alternate representations and a symlink sitting in the workspace all resolve outside the root afterwards. The safety property is established by resolving the path first and then checking that the result is inside an allowed root.
- 5
Schema validation and authorisation
Firing adversarial model outputs at a downstream API, most malformed payloads bounce off schema validation, which then feels like the control. It is not: the request an injection actually produces is well-formed, correctly typed and aimed at somebody else's resource, or asks for a scope wider than the task needs.
- 6
Ranking sinks by reachability
Inheriting a service where one model response builds a SQL query, picks a redirect target, names an S3 key and fills an HTML template, severity ordering puts SQL first and misses the deciding question. A SQL sink fed from a fixed enum is a smaller problem than an HTML sink fed with text from a customer email.
External resources
- LLM05:2025 Improper Output Handlinggenai.owasp.org
The reference definition: XSS, SQLi, path and redirect sinks for model output
- owasp-LLM05: Improper Output Handling with Resolutiongithub.com
Vulnerable app plus the patched version, so you can see both sinks
- Trusting AI Output? Why Improper Output Handling is the New XSSauth0.com
Frames model output as untrusted user input across every downstream sink
- Exploiting Insecure Output Handling in LLMsIntigriti
Walkthrough of turning model text into XSS and command execution
- OWASP Top 10 for LLM05:2025 - Improper Output HandlingVandana Verma
Short structured tour of the risk and the encoding/validation fixes