Summary
A cross-site scripting vulnerability in Discourse allows an unauthenticated attacker to inject arbitrary HTML through a crafted color-scheme cookie. When the value is rendered without escaping, injected script content may execute in visitors' browsers, including in cases where the site's nonce-based Content Security Policy would otherwise provide protection.
Affected context
The issue may occur in Discourse deployments that render color scheme identifiers from client-controlled cookies into a page without applying context-appropriate output encoding. It is particularly risky when an attacker can cause visitors to access a page that processes the crafted cookie and when the resulting markup can bypass or operate outside the intended Content Security Policy protections.
Exploit preconditions
- Attack surface: Discourse web pages that process color scheme cookies
- Required access: No authentication is required; the attacker needs to send or induce a request containing a crafted cookie
- Trigger point: Server-side rendering of the color scheme value into the response
- Why exploitation is possible: The cookie value is inserted into an HTML attribute or tag context without adequate escaping, allowing markup boundaries to be altered and script-capable content to be introduced
Why this happens
The underlying bug is improper neutralization of user-controlled input in an HTML context, mapping to CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). A client-controlled cookie was treated as a trusted color scheme identifier and rendered into page markup without context-aware output encoding. This allowed the value to escape its intended attribute context and create additional HTML, weakening the protection expected from nonce-based Content Security Policy controls.
Potential impact
- Arbitrary JavaScript may execute in visitors' browsers
- User sessions or page actions could be exposed to attacker-controlled script
- Account data or privileged interface content could be accessed subject to browser and application controls
- Attackers could perform actions as affected users
- Site reputation and visitor trust could be harmed
General mitigation guidance
Mitigation generally focuses on enforcing a strict trust boundary for cookie-derived values and ensuring context-appropriate output encoding.
Common defensive patterns include:
- Treating all client-controlled cookies as untrusted input
- Allowing only validated, server-recognized color scheme identifiers
- Applying HTML attribute encoding at the final rendering context
- Avoiding direct interpolation of cookie values into markup
- Preserving CSP as defense in depth rather than relying on nonces to compensate for unsafe HTML generation
- Limiting the privileges available to application sessions and administrative interfaces
- Centralizing output encoding and input validation policies across templates and rendering helpers
How teams detect issues like this
Organizations commonly detect this class of issue through:
- Static analysis for direct interpolation of request, cookie, or header values into HTML templates
- Code review checks for missing context-sensitive output encoding
- Tests that verify special characters in cookie values remain encoded in rendered responses
- Dynamic application testing for reflected script-capable markup in response bodies
- Policy enforcement requiring approved template escaping mechanisms and rejecting unsafe HTML construction
- Monitoring for anomalous cookie values and unexpected script-like content in requests

