Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Security researchers demonstrated in 2023 how an LLM’s response could be turned into an exploit. In one case, an attacker performed a prompt injection on Bing Chat that caused it to output a snippet of markdown for an image with a specially crafted URL. When rendered in a user’s browser, that image URL (in the output) included private data stolen from the conversation, effectively exfiltrating it to the attacker’s server[^1]. This was possible because Bing’s interface did not treat the AI’s answer as untrusted – it directly rendered an image tag, causing the browser to follow the malicious link.
Another illustrative example: a cybersecurity demo showed that by asking an AI coding assistant to generate a script for a simple task, an attacker could embed a dangerous payload in a comment. The AI dutifully included the payload. If the script was run without code review, the payload would execute, demonstrating how AI-written code can hide malicious intent.
These scenarios underscore the need to handle AI outputs with the same caution as any user input.
What happens in this scenario
Insecure output handling is an attack path wherein the AI’s response is used to harm downstream systems or users because its content isn’t properly validated. In enterprise applications, LLMs often feed their output into other processes – for example:
An AI might generate code that is directly executed, produce content displayed on a webpage, or provide data for automated decisions.
If an attacker can influence the prompt or context to produce malicious output, and if that output is not treated as untrusted, the results can be dire.
For instance, an AI-powered report generator might output a piece of text containing a malicious <script> tag.
If a web dashboard displays that output without sanitation, the script could execute in a user’s browser (a cross-site scripting attack).
Likewise, an AI that generates configuration scripts could be coaxed into outputting dangerous commands (e.g. rm -rf *) – if executed automatically, that becomes a remote code execution (RCE) on the server.
In short, the scenario is that unvalidated AI output acts as a new injection vector into any system that consumes it.
Why this technique is effective
Organizations may mistakenly treat AI outputs as trusted because they came from an internal system. Attackers exploit this by combining prompt manipulation with knowledge of how outputs are used. Since LLMs will produce any pattern of text a prompt leads them to, a skilled adversary can craft inputs so that the model’s response includes exploit code or formatted payloads (SQL commands, HTML, shell scripts, etc.). If the next system (application, browser, database, automation script) executes or renders that output without proper checks, the attacker’s payload runs.
This is automation bias: a well-studied human-factors risk where users over-trust system-generated recommendations. The output does not need to be malicious to cause harm; erroneous or misleading AI output can still trigger incidents if the user experience encourages people to accept it without verification, challenge, or appropriate human oversight.
The “distance” between input prompt and harmful action (via multiple systems) can also blindside traditional security, as the exploit manifests in a different part of the pipeline.
Recommended controls
Treat AI outputs as untrusted: Just as user input is considered unsafe until validated, apply the same scrutiny to model outputs. Any data coming out of an LLM that will be fed into interpreters (browsers, shells, SQL engines, etc.) must be sanitized or escaped. For web content, use output encoding to neutralize any HTML/JS (preventing XSS). For code or shell commands, avoid direct execution; if needed, run them in secure sandboxes with limited privileges.
Human or automated review: For critical actions, include review before execution—but design that review carefully. This is easy to state and hard to do well: automation bias and prompt fatigue can cause users to accept AI recommendations without meaningful scrutiny, especially when the interface normalizes frequent approvals.
Automated static analysis tools, linters, and security scanners can help vet AI-generated code for vulnerabilities or malicious patterns.
Human-centered design resources, such as the Microsoft Research HAX Toolkit, can also help teams think through when to warn, when to require confirmation, how to disclose uncertainty, and how to avoid creating review experiences that users learn to ignore.
Limit direct actions: Avoid architectures where the LLM’s output immediately triggers high-impact processes. Insert a verification step. For example, if an AI crafts an SQL query, use parameterized queries or prepared statements rather than executing raw SQL from the model. If an AI composes an email or message, do not auto-send without user confirmation (preventing scenarios where an attacker makes the AI generate and send, say, a phishing email internally).
Segmentation and monitoring: Run components that consume AI output in constrained environments. For example, use containerization or VM sandboxes for any auto-executed code the AI produces, with strict runtime guards (time, memory limits) to mitigate damage from malicious instructions. Monitor logs for patterns such as an unusual sequence of failed commands or suspicious output content.
Technologies to consider
Web Application Firewalls (WAF): Deploy WAF rules to detect and block suspicious patterns in responses just as you would for user input. Modern WAFs can be configured to catch things like script tags in places they shouldn’t be, or large anomalous outputs.
Runtime security & sandboxes: Use containerization and tools like Docker Security features, or solutions such as Azure Container Instances with restricted permissions, to execute AI-generated scripts in isolation. If the AI is part of an automation pipeline (CI/CD, etc.), incorporate security gates (e.g., GitHub branch protection rules, static code analysis via SonarQube or Veracode for AI-written code) before promoting AI-generated changes.
Output post-processing: Leverage libraries or frameworks that can automatically “clean” or validate model outputs. For instance, LangChain or Microsoft Guidance allow defining regex or schema expectations for LLM outputs – if output deviates or contains disallowed content (like unsupported commands), it can be rejected or corrected before use.
DLP and data sanitization tools: If model outputs might contain sensitive data (due to an injection or model leak), use DLP solutions (e.g., Microsoft Purview DLP, Azure Information Protection) to scan and redact secrets, tokens, or PII from outputs before they are displayed or stored.
OWASP Top 10 mapping
OWASP Top 10 for LLM and Generative AI (2025)
This scenario maps to LLM05: Improper Output Handling, where downstream systems act on LLM‑generated content without validation or sanitization, and LLM08: Vector and Embedding Weaknesses, since unsafe outputs can pollute vector stores, mislead retrieval systems, or introduce malicious content into embedding pipelines.
MITRE ATLAS mapping
This scenario maps broadly to MITRE ATLAS behaviors around unsafe output handling, sensitive disclosure, and downstream exploitation.
MITRE ATLAS Techniques (Attack): The attack primarily reflects unsafe downstream handling: model output is treated as trusted content and can trigger exfiltration, script execution, command injection, or workflow compromise when rendered or executed without validation.
- AML.T0024 Exfiltration via AI Inference API
- AML.T0048 External Harms
- AML.T0053 AI Agent Tool Invocation
- AML.T0057 LLM Data Leakage
MITRE ATLAS Mitigations (Defense): Prioritize output encoding, safe rendering, least privilege in downstream systems, sensitive-content classification, and monitoring.
- AML.M0002 Passive AI Output Obfuscation
- AML.M0019 Control Access to AI Models & Data in Production
- AML.M0020 Generative AI Guardrails
- AML.M0024 AI Telemetry Logging