How I Convinced an AI to Hack Itself: Prompt Injection to XSS ️
The AI chat assistant could be manipulated through prompt injection to generate HTML containing an encoded javascript: URL, which the application then rendered without sanitisation. When a user clicked the generated link, the browser executed the JavaScript, achieving cross-site scripting.
medium.com
Published on medium.com
Found XSS in an AI chat feature by manipulating the AI to generate malicious JavaScript. The AI became my unwilling accomplice in hacking the application.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application sanitised direct user input but rendered the AI assistant's output as HTML without sanitisation, assuming the AI's restrictions made its output safe.
Impact
An attacker could execute JavaScript in a victim's browser, potentially leading to session hijacking, phishing, data theft, or keylogging, though the report does not demonstrate these beyond an alert.
What the attacker needed
Access to the AI chat feature; victim clicks a crafted link
The fix
The application should sanitise or escape all AI-generated output before rendering it as HTML, for example by using textContent or a sanitiser such as DOMPurify, and should enforce a strict Content Security Policy.
How it was found
- Interact with the AI chat assistant using normal productivity requests to build context.
- Craft prompts that gradually convince the AI to generate HTML, starting with a harmless styled heading.
- Ask the AI to produce a link whose javascript: scheme is written using HTML character references.
- Send the AI-generated link in the chat and click it to trigger JavaScript execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The chat feature let an AI write formatted replies, and the website displayed that reply as real web page code instead of plain text. By chatting with the AI in a clever way, the researcher made it produce a link that secretly contained a small program. When someone clicked that link, the program ran in their browser, which is called cross-site scripting.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.