How the attack works
An attacker sends a prompt asking the LLM to produce code containing script tags, event-handler attributes like onerror or onclick, javascript: URIs, or data:text/html URIs. The prompt combines this request with a goal like reading cookies, localStorage, sessionStorage, or the page's document body. If the LLM complies and its output is later inserted into a web page without sanitization, the generated code runs in a victim's browser and exfiltrates data. This rule only detects the request asking the LLM to generate the payload — it does not detect the payload being delivered or executed.
Why it matters
If an application feeds LLM output directly into a web page, an attacker can use the model itself to author working cross-site scripting code, leading to session hijacking, credential theft, or exfiltration of page content from anyone who views the injected content.
What you can do
- Never render LLM-generated HTML or JavaScript in a browser without strict sanitization and output encoding.
- Apply a content security policy that blocks inline scripts and event handlers regardless of their source.
- Treat any AI-generated code destined for a web page as untrusted input requiring the same review as user-submitted content.
- Log and review prompts that combine code-generation requests with references to cookies, storage, or document content.
Known benign look-alikes
- Normal HTML form requests without malicious payload patterns
- Legitimate JavaScript event handler questions without exfil payload
- Marketing email template requests
- Educational questions about XSS prevention
- Legitimate CDN script tag generation
- Legitimate localStorage questions for user preferences