SAASMENT

Security skill · Find and fix

Insecure output handling review.

Find and fix places where LLM output is passed to a browser, shell, interpreter, database, or API without validation or encoding. Use when reviewing an LLM app or agent for improper output handling (OWASP LLM10), including XSS, command injection, and unsafe deserialization of model output.

Download .zipInstall via MCPFind and fixMIT
  • AI security
  • Code review

Facts

Category
Find and fix
License
MIT
Tags
  • AI security
  • Code review
Version
1.0.0
Last updated
2026-12-02
Folder
insecure-output-handling-review/
MCP resource
skill://insecure-output-handling-review/SKILL.md
Files
  • SKILL.md
  • LICENSE
  • references/sinks-checklist.md
Standards

Original Saasment content. Saasment is in early access; this skill does not require joining it.

Install via MCP or as files

Connect your client to https://www.saasment.com/api/mcp (see client setup) and call get_skill:

{
  "name": "get_skill",
  "arguments": {
    "slug": "insecure-output-handling-review"
  }
}

Or download the .zip and unpack it into your agent's skills directory:

Terminal, from your project root (user-level: ~/.cursor/skills)

mkdir -p .cursor/skills
curl -fsSL https://www.saasment.com/ai-security/skills/insecure-output-handling-review/download.zip -o /tmp/insecure-output-handling-review.zip
unzip -o /tmp/insecure-output-handling-review.zip -d .cursor/skills
# result: .cursor/skills/insecure-output-handling-review/SKILL.md

Review SKILL.md before enabling a skill. Skills are instructions your agent will follow.

SKILL.md

---
name: insecure-output-handling-review
description: Find and fix places where LLM output is passed to a browser, shell, interpreter, database, or API without validation or encoding. Use when reviewing an LLM app or agent for improper output handling (OWASP LLM10), including XSS, command injection, and unsafe deserialization of model output.
license: MIT
metadata:
  author: Saasment
  version: "1.0.0"
  category: both
  tags: "ai-security, code-review"
---

# Insecure output handling review (find and fix)

License: MIT. Copyright (c) 2026 Saasment. Source: https://www.saasment.com/ai-security/skills/insecure-output-handling-review

Model output is untrusted input to whatever consumes it next. If a prompt (or injected content) can influence the output, then output that reaches a sink such as `innerHTML`, `eval`, `child_process`, a SQL string, a file path, or a URL fetch can become XSS, code execution, SQL injection, path traversal, or SSRF. This skill traces model output to its sinks and applies the same controls you would use for any untrusted user input.

## When to use

- An application renders model output as HTML or markdown, executes it, or feeds it to another system.
- An agent turns model output into shell commands, SQL, file operations, or HTTP requests.
- You are reviewing OWASP LLM Top 10 2026 category LLM10 (Improper Output Handling).

## Safe by default

- Only test systems you own or are authorized to test, in a non-production environment.
- Use inert probes (for example `<b>CANARY-7f3a</b>` or `$(echo CANARY-7f3a)`) that prove interpretation without causing damage. Do not run destructive commands, and do not use real credentials.
- Run generated code only inside a disposable sandbox with no network and no mounted secrets.

## Procedure

1. **Find every consumer of model output.** Search the code for where completions, tool-call arguments, and structured output are used. Typical consumers: UI renderers, template engines, markdown-to-HTML converters, `eval`/`exec`/`Function`, shell wrappers, ORM or raw SQL, file writers, HTTP clients, and downstream services.
2. **Classify each sink** using `references/sinks-checklist.md`: HTML, JavaScript, shell, SQL, file path, URL, deserializer, or another LLM or tool call.
3. **Check what influences the output.** If any untrusted text can reach the prompt (user input, retrieved documents, tool results), treat the output as attacker-influenced at every sink.
4. **Probe with inert canaries.** Cause the model to emit a canary for the sink type and observe whether it is interpreted. Examples: an HTML tag for HTML sinks, a command substitution for shell sinks, a quote character for SQL sinks, `../` for path sinks, a collaborator URL you control for fetch sinks.
5. **Fix by sink type:**
   - HTML: render as text by default. If markdown or HTML is required, use a sanitizer with an allowlist (for example DOMPurify on the client, or a server-side equivalent), disable raw HTML in the markdown renderer, and set a Content-Security-Policy.
   - JavaScript or code: do not `eval` model output. If code execution is a feature, run it in an isolated sandbox with no secrets and no network by default.
   - Shell: avoid shells. Call programs with an argument array and a fixed command allowlist. Validate arguments against a schema.
   - SQL: use parameterized queries. Never let the model write SQL that runs with write access. For read-only analytics, use a read-only role, a row-limited view, and statement timeouts.
   - Paths: resolve against a fixed base directory and reject results that escape it.
   - URLs: allowlist schemes and hosts, block private address ranges, and follow the `ssrf-find-and-fix` skill.
   - Structured output: parse JSON with a strict schema, reject unknown fields, and enforce types and ranges before use. Do not use unsafe deserializers (for example `pickle` or `yaml.load` on untrusted data).
6. **Add a policy layer** for actions with side effects: require user confirmation for destructive or external actions, and log the validated action, not the raw text.
7. **Add regression tests** for each sink using the same canaries.

## Verification

- Re-run each canary. Expected: HTML canaries display as literal text, command and SQL canaries are treated as data, path canaries are rejected, fetch canaries to private or unlisted hosts are blocked.
- Confirm the sanitizer and CSP are active in the deployed build, not only in development.
- Grep the codebase again for `eval`, `new Function`, `dangerouslySetInnerHTML`, `innerHTML`, `shell=True`, `exec(`, and string-built SQL near model-output variables, and confirm each remaining use is justified.
- Confirm tests fail if the sanitization or validation is removed.

## Reporting

For each sink: location, output source, probe used, result before and after the fix. Note any sink that stays risky by design (for example a code-execution sandbox) and the compensating controls.

## References

- OWASP Top 10 for LLM Applications 2026: https://genai.owasp.org/resource/owasp-genai-llm-top-10-2026/
- Companion skills: `xss-find-and-fix`, `sql-injection-find-and-fix`, `ssrf-find-and-fix`, `prompt-injection-review`.

Helper files

LICENSE
MIT License

Copyright (c) 2026 Saasment

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
references/sinks-checklist.md
# Output sink checklist

License: MIT. Copyright (c) 2026 Saasment.

Search terms are starting points, not complete lists. Add the frameworks your project uses.

| Sink | Risk | Search for | Preferred control |
| --- | --- | --- | --- |
| HTML / markdown render | XSS, link and image exfiltration | `innerHTML`, `dangerouslySetInnerHTML`, `v-html`, the Jinja `safe` filter, `Markup(`, `html_safe`, markdown libraries with raw HTML enabled | Render as text, or sanitize with an allowlist, plus CSP |
| JavaScript execution | Code execution | `eval(`, `new Function(`, `vm.runIn`, `exec(`, notebook or code-interpreter tools | Isolated sandbox, no network, no secrets |
| Shell | Command injection | `child_process.exec`, `os.system`, `subprocess(..., shell=True)`, `Runtime.exec`, backticks | Argument arrays, command allowlist, schema validation |
| SQL | SQL injection, data loss | string-built queries, `.raw(`, `execute(f"`, text-to-SQL features | Parameters, read-only role, row and time limits |
| File paths | Path traversal, overwrite | `open(`, `fs.writeFile`, `path.join` with model text | Fixed base directory, resolve then check prefix |
| URLs / HTTP clients | SSRF | `fetch(`, `requests.get`, `http.Get` on model-provided URLs | Host allowlist, private-range block, no redirects to new hosts |
| Deserializers | Code execution | `pickle.loads`, `yaml.load`, `ObjectInputStream`, `unserialize` | Strict JSON with schema validation |
| Template engines | Server-side template injection | `render_template_string`, `Template(`, `eval` in templates | Never build templates from model output |
| Other model or tool calls | Chained injection | tool arguments built from prior model output | Validate arguments, least privilege, user confirmation |
| Logs and dashboards | Log forging, stored XSS in admin tools | model text written to logs or admin UIs | Encode on output, strip control characters |

## Inert probes by sink

- HTML: `<b>CANARY-7f3a</b>` (should appear as literal characters, not bold text)
- Shell: `CANARY-$(echo 7f3a)` (should not be expanded)
- SQL: a value containing a single quote, such as `O'Brien CANARY-7f3a` (should be stored or matched literally)
- Path: `../CANARY-7f3a.txt` (should be rejected)
- URL: a link to a listener you control (should be blocked unless the host is allowed)

Related

Companion skills

Questions

How do I install the Insecure output handling review skill?

Download https://www.saasment.com/ai-security/skills/insecure-output-handling-review/download.zip and unzip it into your agent's skills directory (for example .cursor/skills, .claude/skills, .agents/skills, or .github/skills) so that insecure-output-handling-review/SKILL.md exists. Or connect to https://www.saasment.com/api/mcp and call the get_skill tool with the slug insecure-output-handling-review.

What license is the Insecure output handling review skill under?

It is original Saasment content under the MIT license, stated in the SKILL.md frontmatter and in the LICENSE file in the skill folder.

Is it safe to run this skill?

A skill is a set of instructions your agent follows, so read SKILL.md first. It tells the agent to test only systems you own or are authorized to test, to use test environments and synthetic data, and to avoid destructive probes. Downloading it does not run any code on your machine.

← All security skills

Try the platform.

Open the demo workspace with mock data. No login. Register from the banner when you want early access. No security team. No call.

Try the platform