Stored XSS in "post last edited" option
A stored cross-site scripting flaw existed in the 'post last edited' indicator, where an attacker could inject script that ran when a victim clicked the edit pencil. This could let an attacker steal cookies or run arbitrary code in the victim's browser.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 12 days
- Paid in 12 days
- Disclosed after 3 months
- There are two users: Attacker and Victim.
- Attacker starts a private talk via private message with the Victim.
- Attacker send a message to Victim, then he edits it or deletes it.
- Victim sees the yellow pencil, symbol of the edit.
- Victim clicks on yellow pencil to see the edit and the XSS runs.
Other info: the XSS also runs on topic (video PoC #2). You can find my XSS message on this URL: https://try.discourse.org/t/recommended-reading-for-community-and-foss-enthusiasts/278 It is very dangerous because it can hit many users at the same time.
Impact
XSS can use to steal cookies, password or to run arbitrary code on victim's browser
The hacker selected the Cross-site Scripting (XSS) - Stored weakness. This vulnerability type requires contextual information from the hacker. They provided the following answers:
URL https://try.discourse.org/t/recommended-reading-for-community-and-foss-enthusiasts/278
Verified Yes
Attachments
Context
Discourse is a forum platform, and the report concerns its private messaging feature. A private message is a conversation between two users, and each message can be edited or deleted after it has been sent. When a message is edited, the interface shows a small yellow pencil next to it, and any participant can click that pencil to see the edit history.
The report describes a stored cross-site scripting (XSS) issue in that edit indicator. The researcher rated it high severity (CVSS 8.2) and it was disclosed on 9 July 2018, with a bounty of 256.00 USD.
Setup
The setup is minimal and needs no special tooling beyond two accounts on a Discourse instance:
- An Attacker account.
- A Victim account.
Both users are participants in the same private conversation. The proof of concept was run against the public test instance at try.discourse.org, and the researcher also left a live XSS message in a public topic there:
https://try.discourse.org/t/recommended-reading-for-community-and-foss-enthusiasts/278
Finding it
The victim, a participant in the conversation, sees the yellow pencil shown next to the edited message. That means content controlled by the sender is displayed to the recipient in a context the recipient will interact with. A message that is edited or deleted leaves a stored payload that executes when the victim opens the edit view.
Exploitation
Step 1: Start a private conversation
The Attacker starts a private talk via private message with the Victim. This establishes the conversation in which the victim will later see the edit indicator.
Step 2: Send and then edit or delete the message
The Attacker sends a message to the Victim, then edits it or deletes it. Either action is enough to make the message carry the edit state that produces the yellow pencil.
Step 3: The victim sees the edit indicator
The Victim sees the yellow pencil, the symbol of the edit, next to the message in the conversation.
Step 4: The victim clicks the pencil and the payload runs
The Victim clicks on the yellow pencil to see the edit, and the XSS runs. The XSS runs when the victim clicks the yellow pencil to see the edit.
The same behaviour was reproduced in a topic as well, not only in private messages. The report includes two video attachments.
The researcher also left the XSS message in place on the public test instance at the URL above, so the behaviour could be checked directly.
Root cause
The report does not describe the root cause of the issue. The report does not include the server-side or template code, so the exact escaping failure is not shown; the behaviour is that the stored edit data reaches the DOM as executable content when the edit view is opened.
Impact
As the researcher puts it, XSS can be used to steal cookies, passwords, or to run arbitrary code in the victim's browser. Because the payload is stored in a message and triggered by the recipient's own click on the edit indicator, it does not depend on the victim visiting an attacker-controlled site. The researcher stresses that it is very dangerous because it can hit many users at the same time: in a topic, it can hit many users at the same time, not just a single targeted person.
Fix
The report does not describe the fix that was applied.
Variants to test
- Other edit-related UI: check any element that displays edit metadata (edit count, last editor, edit reason) in private messages and topics. A positive result is a payload executing when another user opens or hovers the element.
- Deletion notices: delete a message and inspect how the deletion is displayed to other participants. A positive result is the same execution path as the edit indicator.
- Topic versus private message: repeat the steps in a public topic. A positive result is execution for any reader who opens the edit view, which widens the affected population.
- Notification and email rendering: where edit information is echoed into notifications or digests, check whether the same data is escaped there. A positive result is execution or markup injection outside the forum page itself.
Hunting notes
This kind of bug tends to hide in secondary UI that renders stored metadata rather than the message body: edit indicators, edit histories, deletion notices and revision views. During recon, look for features where one user's action produces a small piece of state that other users see and can click. The signal is a stored field that is displayed to a different user than the one who supplied it.
The researcher used two accounts, showed the trigger is clicking the edit pencil, and noted the XSS also runs on a topic. Leaving a working payload on the public test instance gave the program a directly verifiable case, and the topic variant showed that the issue could affect many users at once rather than a single victim.
What happened, in plain words
Discourse is a forum platform: a website where people hold conversations in threads called topics. It also has a private messaging feature, where two users can talk in a conversation that other people cannot see. Each message in a conversation can be edited or deleted after it has been sent. When a message is edited, the interface shows a small yellow pencil next to it, and any participant can click that pencil to see what changed.
The researcher found that this yellow pencil could be made to run code in another user's browser. The trick is called stored cross-site scripting, or stored XSS. "Stored" means the harmful content is saved on the forum's server, inside a message, and stays there. "Cross-site scripting" means that content is later turned into code that runs in the browser of whoever views it. In this case the code runs when the victim clicks the pencil to look at the edit history.
The researcher rated the issue high severity (CVSS 8.2). It was disclosed on 9 July 2018, and the bounty was 256.00 USD.
The two users and the test forum
The setup needs nothing more than two accounts on a Discourse instance:
- An Attacker account.
- A Victim account.
Both users take part in the same private conversation. The proof of concept was run against the public test instance at try.discourse.org. The researcher also left a live XSS message in a public topic there:
https://try.discourse.org/t/recommended-reading-for-community-and-foss-enthusiasts/278
That URL is a normal forum topic address: the part after /t/ is the topic's title, and the number at the end identifies the topic. Anyone can open it in a browser to see the message the researcher left behind.
How the researcher found it
The victim, a participant in the conversation, sees the yellow pencil shown next to the edited message. That matters because it means something the sender controls is displayed to the recipient, in a place the recipient is likely to click. A message that is edited or deleted leaves a stored payload that runs when the victim opens the edit view.
Step by step: how the attack works
Step 1: Start a private conversation
The Attacker starts a private talk via private message with the Victim. This creates the conversation in which the victim will later see the edit indicator. A private message is like a sealed letter between two people: other forum users cannot read it, but both participants see the same interface, including the pencil.
Step 2: Send a message, then edit or delete it
The Attacker sends a message to the Victim, then edits it or deletes it. Either action is enough to give the message the "edited" state that produces the yellow pencil. Think of it like writing on a whiteboard and then rubbing part of it out: the board still shows that something was changed, and that mark is what the victim will click.
Step 3: The victim sees the edit indicator
The Victim sees the yellow pencil, the symbol of the edit, next to the message in the conversation. The pencil is a small clickable icon, like the "show changes" button in a word processor.
Step 4: The victim clicks the pencil and the payload runs
The Victim clicks on the yellow pencil to see the edit, and the XSS runs. The XSS runs in the victim's browser when the victim clicks the yellow pencil to see the edit.
The same behaviour was reproduced in a topic as well, not only in private messages. The report includes two video attachments.
The researcher also left the XSS message in place on the public test instance at the URL above, so the behaviour could be checked directly.
Why it works
The report does not describe the root cause of the issue. Escaping means turning characters that a browser would treat as code into plain text, the way you would write "less than" instead of the symbol < so that it is read as a word and not as the start of a tag. Because that step is missing, markup supplied by the sender is interpreted by the recipient's browser.
The report does not include the server-side or template code, so the exact escaping failure is not shown. What is shown is the behaviour: the stored edit data reaches the page as executable content when the edit view is opened.
Impact
As the researcher puts it, XSS can be used to steal cookies, passwords, or to run arbitrary code in the victim's browser. A cookie is a small piece of data a website stores in your browser, often to remember that you are logged in; if someone can read it, they may be able to act as you. Because the payload is stored in a message and triggered by the recipient's own click on the edit indicator, it does not depend on the victim visiting an attacker-controlled site. The researcher stresses that it is very dangerous because it can hit many users at the same time: in a topic, it can hit many users at the same time, not just a single targeted person.
Fix
The report does not describe the fix that was applied.
Variants to test
- Other edit-related UI: check any element that displays edit metadata (edit count, last editor, edit reason) in private messages and topics. A positive result is a payload executing when another user opens or hovers the element.
- Deletion notices: delete a message and inspect how the deletion is displayed to other participants. A positive result is the same execution path as the edit indicator.
- Topic versus private message: repeat the steps in a public topic. A positive result is execution for any reader who opens the edit view, which widens the affected population.
- Notification and email rendering: where edit information is echoed into notifications or digests, check whether the same data is escaped there. A positive result is execution or markup injection outside the forum page itself.
Hunting notes
This kind of bug tends to hide in secondary UI that renders stored metadata rather than the message body: edit indicators, edit histories, deletion notices and revision views. During recon, look for features where one user's action produces a small piece of state that other users see and can click. The signal is a stored field that is displayed to a different user than the one who supplied it.
The researcher used two accounts, showed the trigger is clicking the edit pencil, and noted the XSS also runs on a topic. Leaving a working payload on the public test instance gave the program a directly verifiable case, and the topic variant showed that the issue could affect many users at once rather than a single victim.
Glossary
- Discourse: a forum platform, a website where people hold conversations in topics.
- Topic: a public conversation thread on a forum.
- Private message: a conversation between two users that other users cannot see.
- Edit indicator: the small yellow pencil shown next to a message that has been edited or deleted.
- Stored XSS: cross-site scripting where the harmful content is saved on the server and runs when someone later views it.
- Cross-site scripting (XSS): a vulnerability where content supplied by one user is turned into code that runs in another user's browser.
- Payload: the piece of content that triggers the harmful behaviour.
- Escaping: converting characters that a browser would treat as code into plain text so they are displayed, not executed.
- Cookie: a small piece of data a website stores in your browser, often used to keep you logged in.
- CVSS: a scoring system that rates the severity of a security issue.
- Bounty: a payment made to a researcher who reports a valid security issue.
- DOM: the browser's in-memory model of the page, which scripts can read and change.
- Recon: the information-gathering phase of security testing.
- Metadata: data about data, here information about a message such as whether it was edited.