Unicode whitespace can bypass __Host and __Secure cookie prefix protections
Using certain Unicode whitespace characters in cookie names allows attackers to bypass browser-enforced __Host and __Secure prefix checks and have the server treat the cookie as protected.
Security & privacy PortSwigger Research 3 Sep 2025 Attack Prototype evidence
Published as “Cookie Chaos: How to bypass __Host and __Secure cookie prefixes”
Why it matters
If successful, the bypass can enable XSS, session fixation, or CSRF token hijacking despite the presence of __Host/__Secure cookie protections.
Summary
The author shows that browsers treat cookie names prefixed with Unicode whitespace (e.g., U+2000) as non-prefixed, while some server frameworks strip that whitespace and interpret the name as a protected __Host cookie. They demonstrate this with JavaScript PoCs against Django, ASP.NET, and Java servers using legacy $Version parsing. A Burp Suite custom action is provided to detect vulnerable backends. The evidence consists of manual PoCs and framework-specific observations, but no large-scale deployment data.
What they found 5
- A cookie name prefixed with U+2000 is accepted by the browser as non-prefixed but stripped by Django, resulting in a __Host cookie injection.
“document.cookie= `${String.fromCodePoint(0x2000)}__Host-name=injected; Domain=.example.com; Path=/;`”
- Django uses Python’s .strip() method, which removes a wide range of Unicode whitespace characters from cookie keys.
“Django uses Python’s built-in .strip() method to process cookie keys and values. This method removes a wide range of Unicode whitespace characters, including [133, 160, 5760, 8192-8202, 8232, 8233, 8239, 8287, 12288], effectively treating them as a space.”
- Legacy $Version=1 parsing in Java servers can split a single cookie string into multiple cookies, allowing a forged __Host cookie to bypass prefix checks.
“document.cookie= `$Version=1,__Host-name=injected; Path=/somethingreallylong/; Domain=.example.com;`”
- Safari does not support multibyte Unicode whitespace characters in cookie names, preventing the U+2000 bypass on that browser.
“Interestingly, Safari handles this case differently. It does not support multibyte Unicode whitespace characters in cookie names, which prevents values like U+2000 from being used.”
- A lightweight Burp Suite Custom Action can detect backends vulnerable to these cookie prefix bypasses.
“To help test for the issues discussed here I’ve created a lightweight Custom Action for Burp Suite.”
Caveats 4
- Django responded to my vulnerability report: The official Django documentation has a warning against permitting cookies from untrusted subdomains as this is vulnerable to attacks: https://docs.djangoproject.com/en/5.0/topics/http/sessions/#topics-session-security. As this attack relies on this, this will not be treated as a security vulnerability.
- Django classifies the issue as non-vulnerable because its documentation already warns against untrusted subdomain cookies.
- Safari’s lack of support for multibyte Unicode whitespace mitigates the bypass on that browser.
- The attack relies on server-side trimming behavior that may not be present in all frameworks.
What’s new here 4
- Shows that Unicode whitespace characters can hide __Host/__Secure prefixes from browsers.
- Identifies legacy $Version=1 cookie parsing in Java servers as another bypass vector.
- Documents framework-specific trimming behavior (e.g., Django’s .strip()) that enables the attack.
- Provides a Burp Suite custom action to automatically test for these bypass conditions.