Summary
Mojolicious leaks a stable CSRF session token through a BREACH-style compression oracle when attacker-controlled input is reflected into gzip-compressed responses containing the token.
By repeatedly querying such responses and observing compressed lengths, an attacker can recover the CSRF token and bypass csrf_protect validation under certain deployment conditions.
Affected context
This vulnerability arises in Mojolicious applications that:
- Use versions 4.59 through 9.47
- Enable gzip or similar HTTP response compression
- Embed the CSRF token in hidden form fields using
_csrf_field - Reflect attacker-controlled input in the same compressed response as the CSRF token
Under these conditions, the CSRF token becomes observable via a compression side channel rather than direct output disclosure.
Exploit preconditions
- Attack surface: Web application endpoints that:
- Return gzip-compressed responses
- Include a hidden
csrf_tokenfield generated by_csrf_token/_csrf_field - Echo user-supplied data (query params, form input, headers) in the response body
- Required access: Ability to send repeated HTTP requests and influence reflected content; typically no authentication is required beyond normal user access.
- Trigger point: The attacker crafts inputs so that the reflected data aligns with the token in the compressed response, then observes compressed length variations across many requests.
- Why exploitation is possible: The CSRF token is stable per session and reused verbatim in multiple responses. Compression algorithms reduce redundancy between attacker-chosen text and the token, creating a measurable side channel that reveals the secret value.
Why this happens
The core issue is a design that combines a stable, long-lived CSRF token with compression of mixed secret and attacker-controlled data.
_csrf_token generates and caches a single token per session, and _csrf_field consistently embeds this unchanging token into forms.
When gzip compression is applied to responses that also reflect user input, the application unintentionally implements a BREACH-style compression oracle, falling under CWE-204: Observable Response Discrepancy.
This pattern also undermines CWE-352: Cross-Site Request Forgery (CSRF) defenses, because the secrecy of the token is assumed but eroded by the side-channel exposure.
Potential impact
- An attacker may recover CSRF tokens for targeted user sessions.
- An attacker can bypass CSRF protection and submit forged state-changing requests.
- Session integrity could be weakened, enabling unauthorized actions in the user's context.
- Sensitive application functionality (account changes, transactions, configuration updates) could be manipulated without the user's intent.
General mitigation guidance
Effective mitigations focus on reducing or eliminating compression side channels and strengthening CSRF token handling:
- Avoid mixing secret tokens and attacker-controlled data in the same compressed response whenever practical.
- Prefer per-request or per-form CSRF tokens instead of a single stable token per session, reducing oracle usefulness.
- Consider disabling HTTP compression on responses containing secrets or CSRF tokens, or selectively skipping compression for sensitive endpoints.
- Normalize or limit reflection of user input in responses, especially around areas containing hidden fields or secrets.
- Reinforce CSRF defenses with additional mechanisms (same-site cookies, double-submit cookies, or origin checks) to lessen dependence on a single token.
How teams detect issues like this
Detection typically involves architectural and code-level review:
- Examine view templates and controllers for patterns where hidden CSRF fields are emitted together with reflected user input in compressed responses.
- Use static analysis or linters to flag stable, long-lived CSRF tokens reused across multiple requests and mixed with user-controlled data.
- Review web server and framework configuration for blanket gzip/deflate compression applied to sensitive endpoints.
- Employ security testing tools or custom scripts to simulate BREACH-style probing and observe response size correlations, confirming whether a practical oracle exists.
Automated code review systems and security scanners can assist by highlighting compression of secrets alongside attacker-controlled content and by enforcing policies on CSRF token lifecycle.

