Sitewide Cache Poisoning to Stored XSS
Discourse reflected an unescaped color_scheme_id cookie into the page and cached anonymous responses without that cookie in the cache key, letting an unauthenticated attacker poison the cache and, via a strict-dynamic CSP gadget, run JavaScript for every anonymous visitor. Separately, a TOCTOU race in the image upload pipeline let a low-privileged user swap a temp file so ImageMagick's MSVG coder ran an MSL payload, giving arbitrary file read and write on the server.
slcyber.io
Published on slcyber.io
During a security audit of Discourse, a popular open-source forum platform powering over 22,000 communities including OpenAI, Atlassian, and Cloudflare, we discovered two vulnerabilities affecting default configurations. The first is a cache poisoning issue that escalates to JavaScript execution on every page for…
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
Likely the cookie value was interpolated into HTML without escaping while the anonymous cache key omitted that cookie, and the upload pipeline reused a user-controlled temp path across a check-then-use window.
Impact
An unauthenticated attacker could run JavaScript for every anonymous visitor sitewide, and a Trust Level 0 user could read and write arbitrary files on the server, which the authors say could likely be escalated to remote code execution.
What the attacker needed
No account for the cache poisoning; victim uses a matching User-Agent; attacker hosts a CORS-enabled module; Trust Level 0 account for the file read
How it was found
- Send a request with a crafted color_scheme_id cookie so the injected HTML is rendered and cached
- Request the same path with the same User-Agent but without the cookie to receive the poisoned page
- Inject a modulepreload link so the trusted boot script imports an attacker module
- Upload a file with a .pdf extension that is detected as a JXL image and contains PostScript
- Use the PostScript execution to atomically rename an SVG trigger over the temp file
- Trigger the MSVG coder so the MSL payload reads a file and writes it out
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.
A cookie is a small value your browser sends back to a site, and a cache is a store of ready-made pages served to many visitors. Discourse put the cookie's value into the page without cleaning it and cached the result under a key that ignored the cookie, so one crafted request could plant malicious HTML for everyone else. The second bug is a timing trick: the server checked an uploaded file, then a slow image step gave the attacker time to replace the file before it was processed again.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.