From AI Prompt Injection to Authenticated XSS in a CRM Platform
An AI email reply generator followed instructions embedded in an email and inserted the generated HTML into a reply editor without sanitisation, leading to stored XSS. An attacker could execute JavaScript in the victim's authenticated CRM session and perform actions such as changing the email address or sending invitations.
medium.com
Published on medium.com
Bug Bounty
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.
Context
The target was a CRM platform: a cloud-based application that helps businesses manage customers, sales, contacts and communication. While exploring it, the researcher came across a feature called AI Email Reply Generator, which analyses email threads and generates suggested replies. The user opens an email thread and clicks Generate Reply; the AI reads the thread and writes a draft reply into an HTML-based reply editor.
That design puts untrusted text (the body of an incoming email) in front of a language model whose output is then rendered as HTML in the application. The researcher's question was simple: what happens if the email contains instructions for the AI?
Setup
The write-up describes no special tooling, accounts or versions. The only precondition it establishes is that the victim's CRM mailbox is connected to an address that can receive ordinary external email, and that the victim opens the thread and clicks Generate Reply. The researcher confirmed that a regular email sent from an external mailbox reaches the victim's connected mailbox, so no CRM account is needed on the attacker side.
Finding it
The feature generates replies from email content, so the researcher tested whether that content could influence the output. The idea was to embed instructions in an email asking the AI to include a specific JavaScript payload in its generated response. The AI followed the instructions.

Exploitation
Step 1: Deliver the prompt by email
The researcher sent an email containing a prompt asking the AI to include a specific JavaScript payload in its generated response. The write-up shows the prompt used in a screenshot. Delivery is ordinary email: the attacker sends it from an external mailbox to the address connected to the victim's CRM mailbox.
Step 2: Trigger generation
The victim opens the email thread and clicks Generate Reply. The AI analyses the thread, treats the embedded instructions as part of its task, and produces a response containing the injected HTML.
Step 3: HTML lands in the reply editor unsanitised
The application inserted the generated content into the HTML-based reply editor without proper sanitisation. The browser therefore interpreted the HTML and executed its JavaScript event handler, giving JavaScript execution in the authenticated CRM origin.

Step 4: Work around session cookie protection
The first idea was to steal the victim's session, but the session cookie had protection in place, so that path was closed. The researcher instead looked at using the victim's authenticated session directly from the injected script.
The application exposed its anti-forgery tokens through JavaScript-accessible cookies. That let the injected script read the tokens and issue authenticated same-origin requests, so the script could act as the victim rather than merely run in their browser.
Step 5: Perform authenticated actions
With same-origin, token-bearing requests available, the researcher performed several unauthorised actions:
- Changing the victim's registered email address.
- Sending invitations to arbitrary email addresses using the victim's privileges.
- Privilege escalation, including actions involving higher-level privileges.
- Modifying account settings and other authenticated operations.
The write-up does not include the individual requests or responses for these actions.
The chain as summarised in the report
- Attacker sends a crafted email to the victim.
- No CRM account is required.
- Victim opens the email thread.
- Victim clicks Generate Reply.
- AI follows the embedded instructions.
- Generated HTML is inserted into the reply editor without proper sanitisation.
- JavaScript executes in the authenticated CRM origin.
- Attacker performs actions using the victim's privileges.
Root cause
The chain has two links. The first is prompt injection: the model treats text from an untrusted email as instructions, so an attacker who can send mail to the connected mailbox controls part of the generated output. The second, and the one that turns a bad draft into code execution, is that the generated content is inserted into the HTML-based reply editor without proper sanitisation. The model's output is treated as trusted markup even though its input is attacker-controlled.
The session cookie protection limited cookie theft but did not limit the attack, because the anti-forgery tokens were exposed through JavaScript-accessible cookies. A script running in the origin could read them and make authenticated same-origin requests itself, so CSRF-style token defences provided no barrier once script execution was achieved. The write-up does not describe the server-side code, so the precise location of the missing sanitisation is not stated.
Impact
An attacker with no account on the CRM platform can send an ordinary email from an external mailbox to the victim's connected mailbox. If the victim opens the thread and clicks Generate Reply, JavaScript runs in the authenticated CRM origin and the attacker can act with the victim's privileges: change the registered email address, send invitations to arbitrary addresses, escalate privileges including actions involving higher-level privileges, and modify account settings and other authenticated operations. The write-up does not quantify how many users or which roles were affected beyond this.
Fix
The write-up does not say what was changed, if anything. Based on the described behaviour, the generated reply should not be inserted into the editor as HTML without proper sanitisation, and the model's output should be treated as untrusted content regardless of what the input email asked for. Anti-forgery tokens should not be readable from JavaScript where the application can avoid it.
Variants to test
- Other AI-assisted compose or reply features. Send an email whose body asks the assistant to include HTML or a script payload in its draft, then trigger generation. A positive result is the payload appearing in the editor and executing.
- Other sinks for model output. Look beyond the reply editor at summaries, suggested subjects, ticket notes or chat panes that render generated text. A positive result is any sink that interprets the generated markup.
- Token exposure in cookies. Check whether anti-forgery or similar tokens are readable from JavaScript. A positive result is a script in the origin reading the token and completing an authenticated state-changing request.
- Session cookie protections. Confirm whether the session cookie resists script access; if it does, test whether same-origin requests from injected script still succeed, as they did here.
- Delivery paths without an account. Verify that an external mailbox can reach the connected inbox and that no CRM-side interaction is needed before the victim clicks the generate action.
A note on timing
The researcher found the issue right before an exam, with another exam the following day, and postponed reporting it. By the time the report was submitted it had already been marked as a Duplicate.

What happened, in plain words
A security researcher was looking around a CRM platform. CRM stands for Customer Relationship Management: it is a cloud-based application that businesses use to keep track of customers, sales, contacts and communication with those contacts. Think of it as a very large shared address book plus inbox plus notebook that a whole company logs into.
While exploring, the researcher found a feature called AI Email Reply Generator. It uses an AI (a language model, the kind of software behind chat assistants) to read an email thread and write a suggested reply for you. You open an email thread and click Generate Reply; the AI reads the conversation and types a draft reply into an HTML-based reply editor. HTML is the language web pages are written in, and an HTML-based editor is one that shows formatted text (bold, links, line breaks) rather than plain characters.
That design puts text the researcher does not control (the body of an incoming email) in front of the AI, and then puts the AI's answer on the screen as HTML. The researcher asked a simple question: what happens if the email contains instructions for the AI?
The answer: the AI obeyed the email, the reply editor displayed the AI's output as real HTML, and a small piece of JavaScript (the programming language browsers run inside web pages) executed inside the victim's logged-in CRM session. From there the researcher could change the victim's email address, send invitations, escalate privileges and change account settings, all without ever having an account on the CRM platform. The report was submitted late and was marked as a Duplicate, meaning someone else had already reported the same issue.

The pieces you need to know before the story makes sense
Before walking through the steps, here are the ideas the report leans on, explained from zero.
- A web application and its origin. When you log into a site, your browser is talking to a server. The combination of protocol, hostname and port (for example, the site you see in the address bar) is called the origin. Code running in one origin is not supposed to be able to read data from another origin. That rule is one of the main walls protecting your accounts, and the whole finding is about breaking through it from the inside.
- Cookies. A cookie is a small piece of text a website asks your browser to store and send back with every request to that site. It is how a site remembers that you are logged in: after you sign in, the server sets a session cookie, and your browser shows it on every subsequent request like a wristband at an event. If someone steals your wristband, they can walk around as you.
- JavaScript-accessible cookies. Some cookies are deliberately hidden from JavaScript (a flag called HttpOnly does this); others are not. If a cookie is not hidden, any script running on the page can read it. The report says the anti-forgery tokens were exposed this way.
- Anti-forgery tokens (CSRF tokens). CSRF stands for Cross-Site Request Forgery. It is an attack where a different website quietly makes your browser send a request to a site you are logged into, so the request carries your cookie and looks legitimate. To stop this, sites include a secret random value, the anti-forgery token, in each form or request; a foreign site cannot guess it. The token only works if an attacker cannot read it.
- Same-origin requests. A request sent by code running on the same origin as the site itself. Because it comes from the site's own pages, the browser attaches the site's cookies and the site treats it as coming from a logged-in user.
- Prompt injection. A language model does not really distinguish between "the instructions my developer gave me" and "text that happens to be in the input". If you can put text into the input, you can try to make the model follow it. It is like handing a translator a letter and having them translate your note in the margin as if it were part of the letter.
- XSS (Cross-Site Scripting). A vulnerability where an attacker gets their own JavaScript to run inside someone else's browser session on a site. Stored XSS means the malicious content is saved somewhere (here, generated into a reply) and runs when the victim views it. The impact is that the script runs with the victim's privileges.
- Sanitisation. Cleaning user-supplied or generated content so that anything that looks like HTML or script is neutralised before it is displayed. If a site skips this, the browser cannot tell the difference between the site's own markup and an attacker's.
- Payload. The actual malicious content an attacker wants to deliver, in this case a snippet of JavaScript.
- Duplicate. Bug bounty platforms let researchers submit findings; if two people report the same issue, the later one is marked duplicate and usually gets no reward.
Setup
The write-up describes no special tooling, accounts or versions. The only precondition it establishes is that the victim's CRM mailbox is connected to an address that can receive ordinary external email, and that the victim opens the thread and clicks Generate Reply. The researcher confirmed that a regular email sent from an external mailbox reaches the victim's connected mailbox, so no CRM account is needed on the attacker side.
In plain terms: the attacker only needs an ordinary email account somewhere on the internet. The victim needs a CRM account whose mailbox is linked to an address that can receive mail from outside. Nothing else is required.
Finding it
The feature generates replies from email content, so the researcher tested whether that content could influence the output. The idea was to embed instructions in an email asking the AI to include a specific JavaScript payload in its generated response. The AI followed the instructions.

Why this step matters: the researcher is not attacking the CRM's login, its network or its database. The researcher is attacking the input to the AI. If the AI treats the email body as instructions, then anyone who can send an email to the connected mailbox can influence what the AI writes. That is the first link in the chain.
Exploitation
Step 1: Deliver the prompt by email
The researcher sent an email containing a prompt asking the AI to include a specific JavaScript payload in its generated response. The write-up shows the prompt used in a screenshot. Delivery is ordinary email: the attacker sends it from an external mailbox to the address connected to the victim's CRM mailbox.
Why this step was taken: the AI only reads what is in the thread. To get instructions in front of it, the instructions have to arrive as part of the conversation, which means as an email. No CRM login, no special access, just a normal message.
Step 2: Trigger generation
The victim opens the email thread and clicks Generate Reply. The AI analyses the thread, treats the embedded instructions as part of its task, and produces a response containing the injected HTML.
Why this step matters: the victim does something completely normal. They read an email and ask the assistant for a draft reply. Nothing about that click looks suspicious, which is exactly why the attack is dangerous: the victim is the one who triggers it, without knowing.
Step 3: HTML lands in the reply editor unsanitised
The application inserted the generated content into the HTML-based reply editor without proper sanitisation. The browser therefore interpreted the HTML and executed its JavaScript event handler, giving JavaScript execution in the authenticated CRM origin.

Why this step matters: this is the moment the problem stops being "the AI wrote something odd" and becomes "code is running". The reply editor is supposed to show a draft reply. Instead it treats the AI's output as page markup, and the browser does what browsers do with markup: it renders it and runs any script attached to it. Because this happens inside the CRM page the victim is logged into, the script runs with the victim's logged-in context.
Step 4: Work around session cookie protection
The first idea was to steal the victim's session, but the session cookie had protection in place, so that path was closed. The researcher instead looked at using the victim's authenticated session directly from the injected script.
The application exposed its anti-forgery tokens through JavaScript-accessible cookies. That let the injected script read the tokens and issue authenticated same-origin requests, so the script could act as the victim rather than merely run in their browser.
Why this step matters: the obvious goal after getting script execution is to take the victim's login away, so the attacker can use it later from their own machine. The session cookie's protection blocked that. So the researcher changed tactics: instead of stealing the login, use the browser the victim is already sitting in. The script does not need to leave the page; it can send requests from inside the CRM, and the browser will attach the victim's cookies automatically. The only obstacle is the anti-forgery token, and because that token was readable from JavaScript, the script could pick it up and include it in its own requests. The defence that stops a foreign site from forging requests does nothing against code that is already running on the site itself.
Step 5: Perform authenticated actions
With same-origin, token-bearing requests available, the researcher performed several unauthorised actions:
- Changing the victim's registered email address.
- Sending invitations to arbitrary email addresses using the victim's privileges.
- Privilege escalation, including actions involving higher-level privileges.
- Modifying account settings and other authenticated operations.
The write-up does not include the individual requests or responses for these actions.
Why each action matters:
- Changing the registered email address. The email address on an account is often the recovery route: password resets go there.
- Sending invitations. Invitations come from the victim's account and carry the victim's authority.
- Privilege escalation. The report lists privilege escalation, including actions involving higher-level privileges.
- Modifying account settings.
The chain as summarised in the report
- Attacker sends a crafted email to the victim.
- No CRM account is required.
- Victim opens the email thread.
- Victim clicks Generate Reply.
- AI follows the embedded instructions.
- Generated HTML is inserted into the reply editor without proper sanitisation.
- JavaScript executes in the authenticated CRM origin.
- Attacker performs actions using the victim's privileges.
Read as a story: an email arrives, the victim asks the assistant for a reply, the assistant obeys the email instead of the victim, the editor displays the assistant's answer as code, the code runs as the victim, and the code uses the victim's own logged-in browser to do things the victim never asked for. At no point does the attacker need a password, a CRM account or access to the victim's machine.
Root cause
The chain has two links. The first is prompt injection: the model treats text from an untrusted email as instructions, so an attacker who can send mail to the connected mailbox controls part of the generated output. The second, and the one that turns a bad draft into code execution, is that the generated content is inserted into the HTML-based reply editor without proper sanitisation. The model's output is treated as trusted markup even though its input is attacker-controlled.
The session cookie protection limited cookie theft but did not limit the attack, because the anti-forgery tokens were exposed through JavaScript-accessible cookies. A script running in the origin could read them and make authenticated same-origin requests itself, so CSRF-style token defences provided no barrier once script execution was achieved. The write-up does not describe the server-side code, so the precise location of the missing sanitisation is not stated.
In everyday terms: the AI is like a translator who will follow any note slipped into the letter, and the editor is like a printer that will print whatever the translator hands back, including instructions to the printer itself. Either one alone is a problem; together they let a stranger's email turn into actions on your account.
Impact
An attacker with no account on the CRM platform can send an ordinary email from an external mailbox to the victim's connected mailbox. If the victim opens the thread and clicks Generate Reply, JavaScript runs in the authenticated CRM origin and the attacker can act with the victim's privileges: change the registered email address, send invitations to arbitrary addresses, escalate privileges including actions involving higher-level privileges, and modify account settings and other authenticated operations. The write-up does not quantify how many users or which roles were affected beyond this.
The important part for a beginner: the attacker never logs in. The victim's own browser, already logged in, does the work. That is why this class of bug is serious even when passwords and session cookies are protected.
Fix
The write-up does not say what was changed, if anything. Based on the described behaviour, the generated reply should not be inserted into the editor as HTML without proper sanitisation, and the model's output should be treated as untrusted content regardless of what the input email asked for. Anti-forgery tokens should not be readable from JavaScript where the application can avoid it.
Variants to test
If you want to look for similar issues yourself, these are the directions the finding suggests. Each one is a question you can ask about a feature you use.
- Other AI-assisted compose or reply features. Send an email whose body asks the assistant to include HTML or a script payload in its draft, then trigger generation. A positive result is the payload appearing in the editor and executing.
- Other sinks for model output. Look beyond the reply editor at summaries, suggested subjects, ticket notes or chat panes that render generated text. A positive result is any sink that interprets the generated markup.
- Token exposure in cookies. Check whether anti-forgery or similar tokens are readable from JavaScript. A positive result is a script in the origin reading the token and completing an authenticated state-changing request.
- Session cookie protections. Confirm whether the session cookie resists script access; if it does, test whether same-origin requests from injected script still succeed, as they did here.
- Delivery paths without an account. Verify that an external mailbox can reach the connected inbox and that no CRM-side interaction is needed before the victim clicks the generate action.
A note on timing
The researcher found the issue right before an exam, with another exam the following day, and postponed reporting it. By the time the report was submitted it had already been marked as a Duplicate.

The lesson is not about the technical work, which was sound. It is about the queue: on a bug bounty platform, the same bug can be found by several people, and the first report submitted is the one that counts. Waiting, even for a good reason, can turn a valid finding into a duplicate.
Glossary
- AI (language model): software trained on large amounts of text that can read an input and produce a written response, such as a suggested email reply.
- Anti-forgery token (CSRF token): a secret random value a site includes in requests so that a different website cannot forge them; it only protects if an attacker cannot read it.
- Authenticated: acting as a logged-in user, with that user's permissions.
- Bug bounty platform: a service where researchers submit security findings to companies and may receive a reward.
- Cookie: a small piece of text a website stores in your browser and receives back on later requests, commonly used to remember that you are logged in.
- CRM (Customer Relationship Management): a cloud application businesses use to manage customers, sales, contacts and communication.
- CSRF (Cross-Site Request Forgery): an attack where another website makes your browser send a request to a site you are logged into, so the request appears to come from you.
- Duplicate: a submitted report that describes an issue someone else already reported; usually not rewarded.
- HTML: the language web pages are written in; it describes structure and formatting, and can include script.
- HTML-based reply editor: an editor that displays formatted content rather than plain text, meaning it interprets HTML.
- HttpOnly: a cookie flag that hides the cookie from JavaScript; the report says the session cookie had protection in place.
- JavaScript: the programming language browsers run inside web pages; it can read page data and send requests.
- JavaScript event handler: a piece of JavaScript attached to an HTML element that runs when something happens, such as the page loading.
- Origin: the combination of protocol, hostname and port that identifies a site; code from one origin is not supposed to read another origin's data.
- Payload: the malicious content an attacker wants to deliver, here a snippet of JavaScript.
- Privilege escalation: performing actions with more authority than your role should allow.
- Prompt injection: getting an AI to follow instructions hidden in its input rather than the instructions its developer intended.
- Same-origin request: a request sent by code running on the same origin as the site, so the browser attaches that site's cookies and the server treats it as the logged-in user.
- Sanitisation: cleaning content so that anything resembling HTML or script is neutralised before display.
- Session: the period during which a site remembers you as logged in, tracked by a session cookie.
- Session cookie: the cookie that identifies your logged-in session; stealing it usually means impersonating you.
- Stored XSS: Cross-Site Scripting where the malicious content is saved or generated and runs when a victim views it.
- XSS (Cross-Site Scripting): a vulnerability that lets an attacker's JavaScript run inside another user's browser session on a site, with that user's privileges.