Cyber Security News

New Cookie Sandwich Technique Let Attackers Bypass HttpOnly Flag On Servers

A newly discovered attack technique, dubbed the “cookie sandwich,” enables attackers to bypass the HttpOnly flag on certain servers, exposing sensitive cookies, including session identifiers, to client-side scripts.

The “cookie sandwich” attack exploits flaws in how web servers parse cookies when special characters, quotes, and legacy attributes are introduced. 

By strategically crafting cookie headers, attackers can manipulate the server’s interpretation of cookie structures, effectively exposing HttpOnly cookies.

Key Mechanisms Of The Attack

Legacy Cookie Parsing: Many web servers support both modern (RFC6265) and legacy (RFC2109) cookie standards. If a cookie header begins with a $Version attribute, servers often default to legacy parsing logic.

Investigate Real-World Malicious Links & Phishing Attacks With Threat Intelligence Lookup - Try for Free

Quoted Strings: Legacy parsing allows quoted strings in cookie values. The parser continues reading until it encounters an unescaped closing quote (“), potentially including unrelated cookies within the quoted value.

Backslash Unescaping: Characters preceded by a backslash (\) are unescaped during parsing, further complicating cookie handling.

Create a cookie sandwich to steal a restricted cookie value
Server interprets

Zakhar Fedotkin, a security researcher at PortSwigger, said if the application reflects the param1 value in its response or lacks proper escaping mechanisms, the entire string—including the sensitive sessionId—can be exposed.

In one proof-of-concept attack, researchers exploited an XSS vulnerability on a vulnerable application running Apache Tomcat:

XSS Injection: JavaScript was injected into an error page due to improper input sanitization.

Cookie Manipulation: The script set $Version, param1, and param2 cookies to create the “sandwich.”

Reflection Exploitation: The manipulated cookies were reflected in a JSON response from a tracking domain, exposing the HttpOnly PHPSESSID cookie.

A crafted request
Server response

Impact And Vulnerable Systems

This vulnerability affects web applications relying on legacy parsing or frameworks that support quoted strings by default (e.g., Python Flask). 

Note that the RFC2109 is supported by default in Apache Tomcat versions 8.5.x, 9.0.x, and 10.0.x.

Hence, this technique leverages XSS, cookie manipulation, and the tracking application’s vulnerability.

The “cookie sandwich” technique underscores the importance of robust cookie security practices and careful handling of legacy compatibility features. 

As attackers continue to exploit overlooked vulnerabilities, organizations must proactively update their systems and adopt modern security standards to safeguard user data.

Integrating Application Security into Your CI/CD Workflows Using Jenkins & Jira -> Free Webinar

Guru Baran

Gurubaran KS is a cybersecurity analyst, and Journalist with a strong focus on emerging threats and digital defense strategies. He is the Co-Founder and Editor-in-Chief of Cyber Security News, where he leads editorial coverage on global cybersecurity developments.

Recent Posts

NSA, CISA and NIST Release New Security Guidelines to Detect and Shut Down Rogue AI Agents

NSA, CISA, and NIST have released joint security guidelines to help organizations detect, contain, and…

3 hours ago

Hackers Exploit SiteGuard WAF Vulnerability That Could Give Them Full Control of Servers

Hackers are exploiting a command injection flaw in SiteGuard Server Edition, a web application firewall…

3 hours ago

Hackers Registered New Teams-Based Domains and Used a Login Page to Steal Your Logins

A newly registered domain copies Microsoft Teams’ login page and interface, raising concerns about a…

3 hours ago

16-Year-Old Broadcom Wi-Fi Flaw Lets Attackers Hack Routers Without Knowing Passwords

A 16-year-old flaw in Broadcom’s Wi-Fi software can let attackers within wireless range take control…

3 hours ago

Google Unveils New Android AI Protections to Block Scam Calls, Phishing Links and OTP Theft

Google has announced a new set of Android security protections designed to stop mobile scams…

9 hours ago

Hackers Exploiting Plex Vulnerabilities in the Wild to Deploy Cryptominer Malware

Hackers are exploiting flaws in Plex Media Server to install cryptocurrency mining malware, with a…

11 hours ago