Full Report
Cookies are a major place for security in the browser. They can hold secrets via the HTTPOnly place, can only be sent over HTTPs via the Secure flag and help to prevent CSRF via the SameSite flag. We always assume that cookies operate correctly. There are many fields in a cookie, such as the path, expire time, host and more. However, when we have specific primitives, we can cause massive damage when cookies aren't being handled as they should. The authors of this paper consider a few different scenarios. First, a same site attacker from our a sub-domain takeover, bad site design or XSS. The second, is the same but without an HTTPs/TLS connection. The final attacker they consider is a user with full control over the cleartext traffic being sent back via a MitM attack. These specific roles are important, as they grant the user access to specific abilities in the browser. There are some old-school techniques to talk about. First, cookie tossing. Only the first cookie sent in the request of a particular name is parsed by most web servers. So, how are cookies of the same name ordered? First, it's sorted by path then creation time. If an attacker can set a cookie on one domain with a value with a more specific path, then it will get parsed first! For the double submit CSRF pattern, this is a devastating attack. Second, the cookie jar has a limit on FF and Chrome of 180 per schemeful site with oldest cookies getting kicked out. So, an attacker can set a ton of cookies to boot out even HTTPOnly cookies. Nameless cookies are a cookie with a value but not a name, which was added to the specification in 2020 because many servers were doing this anyway. However, as cookies are just strings, the security implications of concatenating regular cookies with nameless cookies was NOT considered. When taking a nameless cookie like =sid=evil; it would be parsed as sid=evil;. This could even be used to bypass the host cookie and secure cookies from an insecure origin. Firefox and Chrome followed the standard to the tee, resulting in CVEs on their side. The solution was to drop nameless cookies that beginning with __Host or __Secure. They decided to see how cookies were being parsed on the server-side. Since there wasn't a set standard on this, many browsers and servers differ in this aspect. For instance, in PHP, all dots, spaces and square brackets are rewritten to be underscores instead. So, an attacker can spoof a secure or host only cookie by doing ..Host-sid=evil, which will be translated into __Host-sid=evil. ReactPHP URL decoded the cookie name, causing a similar type of issue. Wekzeug, which is used by Flask, and API gateway from AWS, removed leading equal signs leading to the same issue as before. FireFox had an issue that desyncs the actual cookies being sent versus what was returned by the Document.cookie API. Since HTTP headers, like CSRF tokens, often use cookies, this could create an issue. To find these types of issues, they reviewed the cookie standard thoroughly then tested both browsers and server parsing. Discrepancies would cause interesting desync issues like mentioned above. Cookie fixation is a method is setting a cookie as an attacker then having this value be used for the service down the road. For session cookies and CSRF protections, this can be real bad, as an attacker would know a secret value to bypass protections. They found that many frameworks would use a CSRF token set as a cookie on the site prior to login would also use it while authenticated. They found that Express/Koa/Fastify in the NodeJS stack, Symfony, Flask and CodeIgniter4 were vulnerable to this fixation issue. They found that Passport, Fastify and Sails frameworks were vulnerable to trivial session fixation vulnerabilities by simply setting the session cookie prior to login. Yikes! That's an easy account takeover. Overall, an amazing set of tricks and things to keep in mind when trying to escalate XSS on a crappy domain or a sub domain takeover. Both old and new things were presented which was awesome.
Analysis Summary
# Research: Analysis of HTTP Cookie Parsing Discrepancies and Session Fixation
## Metadata
- **Authors:** *Not explicitly named in the provided text* (Note: This research aligns with the work presented by researchers like **Marco Squarcina** or similar groups focusing on web security at Black Hat/USENIX).
- **Institution:** *Not explicitly named* (Commonly affiliated with institutions like TU Wien or similar cybersecurity labs).
- **Publication:** *Summarized from a technical security analysis/research paper.*
- **Date:** Post-2020 (References the 2020 cookie specification updates).
## Abstract
This research explores the fragile security assumptions underlying the HTTP cookie mechanism. By analyzing discrepancies between browser storage logic and server-side parsing, the authors demonstrate how attackers can bypass security flags like `__Host-` and `__Secure-`, perform cookie "tossing," and execute session fixation attacks. The study highlights that even modern specifications, such as "nameless cookies," introduced unforeseen vulnerabilities that allow for the displacement of legitimate, secure cookies.
## Research Objective
The research aims to answer:
1. How do discrepancies between browser implementations and server-side parsers lead to security bypasses?
2. Can an attacker on a subdomain or a MitM position displace or spoof `HTTPOnly`, `Secure`, and `Host-only` cookies?
3. To what extent do modern web frameworks remain vulnerable to session and CSRF token fixation?
## Methodology
### Approach
The authors employed a dual-track testing methodology:
- **Specification Review:** A thorough audit of the RFCs and the 2020 cookie standard updates.
- **Differential Testing:** Testing how various browsers (Chrome, Firefox) and server-side frameworks (PHP, Flask, Express, etc.) interpret identical, malformed, or specifically ordered cookie strings.
### Dataset/Environment
- **Browsers:** Google Chrome, Mozilla Firefox.
- **Server-side Frameworks:** PHP, ReactPHP, Werkzeug (Flask), AWS API Gateway, Express, Koa, Fastify, Symfony, CodeIgniter4, Passport, and Sails.
### Tools & Technologies
- Manual testing of `Document.cookie` API vs. HTTP headers.
- Custom scripts for automated cookie parsing differential analysis.
## Key Findings
### Primary Results
1. **Nameless Cookie Vulnerabilities:** Browsers followed the 2020 spec for nameless cookies (e.g., `=value`) so literally that it allowed attackers to inject strings that servers parsed as named cookies (e.g., `sid=evil`), effectively bypassing `__Host-` prefixes.
2. **Server-Side Normalization Issues:** Many servers transform cookie names (e.g., PHP converting `.` to `_`), allowing attackers to spoof protected `__Host-` cookies using sequences like `..Host-`.
3. **Cookie Jar Eviction:** Attackers can bypass `HTTPOnly` protections by "flooding" the cookie jar (hitting the ~180 cookie limit) to force the eviction of legitimate, secure cookies.
4. **Widespread Fixation:** Multiple high-profile frameworks (Passport, Fastify, Sails) were found vulnerable to session fixation, while others (Express, Flask, Symfony) failed to rotate CSRF tokens upon authentication.
### Supporting Evidence
- **CVE Generation:** Discrepancies in Chrome and Firefox regarding nameless cookies resulted in assigned CVEs.
- **Parser Discrepancies:** Werkzeug and AWS API Gateway were found to strip leading `=` signs, creating parsing desyncs.
### Novel Contributions
- Identification of the "Nameless Cookie" attack vector following the 2020 specification update.
- Discovery of "Path-based sorting" exploits to ensure malicious cookies are parsed before legitimate ones.
## Technical Details
- **Cookie Tossing & Ordering:** Web servers typically parse only the first instance of a cookie name. Browsers sort cookies by **Path length** (most specific first) then by **Creation time**. An attacker can "shadow" a global cookie by setting one with a more specific path (e.g., `/app` vs `/`).
- **PHP Normalization:** PHP’s internal logic converts dots (`.`), spaces (` `), and square brackets (`[`) into underscores. An attacker setting `..Host-session=evil` results in the server seeing `__Host-session=evil`, bypassing the browser's restriction that prevents non-secure origins from setting `__Host-` cookies.
## Practical Implications
### For Security Practitioners
- Subdomain takeovers are higher risk than previously thought; they can be used to "toss" cookies onto the main domain that overwrite or precede legitimate session identifiers.
### For Defenders
- **Prefixes:** Use `__Host-` and `__Secure-` prefixes, but ensure the server-side parser does not "normalize" other characters into these prefixes.
- **Rotation:** Ensure session IDs **and** CSRF tokens are regenerated immediately upon any change in privilege level (login).
### For Researchers
- The "gap" between browser behavior and server-side parsing (Differential Analysis) remains a fertile ground for discovering bypasses in supposedly "solved" technologies like cookies.
## Limitations
- The effectiveness of "Cookie Tossing" depends on the specific server-side parser (some may parse all cookies, though most take the first).
- Many attacks require a primitive (XSS on a subdomain, subdomain takeover, or MitM) to begin.
## Comparison to Prior Work
While cookie fixation and tossing are "old-school" techniques, this research updates the threat model by applying these concepts to modern browser features (the 2020 nameless cookie spec) and modern JavaScript-heavy frameworks (NodeJS stack).
## Real-world Applications
- **Account Takeover:** Exploiting session fixation in frameworks like Passport or Sails to pre-set a victim's session.
- **CSRF Bypass:** Overwriting a `Double Submit Cookie` CSRF token via path-based cookie tossing.
## Future Work
- Investigating how "Partitioned Cookies" (CHIPS) might affect these displacement attacks.
- Developing standardized, strict cookie parsing libraries for server-side frameworks to prevent character normalization issues.
## References
- RFC 6265 (HTTP State Management Mechanism)
- *Related Research:* [https://cve.mitre.org/](https://cve.mitre.org/) (Search for browser cookie parsing CVEs)
- *Technical Blog:* [https://portswigger.net/research](https://portswigger.net/research) (General context on desync attacks)