← Lab /Security & privacy

Cache poisoning in Discourse enables JavaScript execution for all anonymous users

Discourse's default configuration allows unauthenticated attackers to achieve JavaScript execution for any anonymous visitor via cache poisoning and to read arbitrary files through a TOCTOU race in the image upload pipeline.

Security & privacy Assetnote / Searchlight 7 Oct 2026 Disclosure Real-world evidence

Published as “A JPEG, a Race, and a Ghost: Breaking Discourse's Image Pipeline”

Why it matters

These bugs let an unauthenticated attacker execute JavaScript in any visitor’s browser and read arbitrary files from the server, potentially leading to full compromise of thousands of Discourse sites.

Summary

The researchers examined Discourse's default Docker deployment and found that a crafted color_scheme_id cookie can inject HTML into cached pages, which is then served to all anonymous users. By leveraging a strict-dynamic CSP gadget in Discourse's boot script, the injected link tag triggers a remote module import, giving the attacker full JavaScript execution in the victim's browser. Separately, they discovered a TOCTOU race in the image upload flow that, combined with ImageMagick and Ghostscript behavior, enables PostScript execution and arbitrary file read/write on the server. Both issues were demonstrated on a fresh Discourse instance and reported to the vendor for patching.

What they found 1

  1. Cache poisoning allows JavaScript execution for all anonymous visitors

    “Discourse caches rendered pages for anonymous visitors in Redis (anonymous_cache.rb). The cache key includes the request path, Accept header, URL scheme, host, and User-Agent, but not the color_scheme_id cookie (source)! When a poisoned response is cached, every subsequent anonymous visitor with the same User-Agent receives the injected HTML.”

Caveats 1

  • The main limitation is that the race window is extremely narrow, too small to be realistically triggered as-is.

What’s new here 4

  • Cache poisoning via an unvalidated color_scheme_id cookie that bypasses CSP and affects all anonymous visitors.
  • Identification of a strict-dynamic CSP gadget in Discourse's boot script that loads attacker-controlled modulepreload links.
  • A TOCTOU race in the image upload pipeline that allows PostScript execution through ImageMagick and Ghostscript.
  • Use of a JPEG bomb to widen the race window and achieve reliable arbitrary file read without a zero-day.