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

Hackers Target AI Infrastructure With RCE, Prompt Injection and API Key Theft

Hackers are actively probing AI systems, turning exposed gateways and agent tools into routes for…

2 hours ago

Hackers Make Phishing Pages Change Their Code Every Time Someone Opens Them

Hackers are making some phishing pages harder to track by changing the code delivered to…

3 hours ago

Iran-Linked Hackers Reportedly Knock UK Power Plant Offline for Four Days

A cyber incident reportedly forced a British power plant to halt operations for about four…

4 hours ago

Russian Hackers Use New HOOKEDGE Malware to Spy on European Defense and Diplomatic Targets

Russian hackers have used a new backdoor called HOOKEDGE to target defense manufacturers, government bodies,…

4 hours ago

Ransomware Gang Claims AI Can Analyze 700GB of Stolen Data Every Hour

TITAN ransomware is pairing file encryption with an ambitious claim: artificial intelligence that can sort…

4 hours ago

Hackers Compromise Hundreds of WordPress Sites to Deploy Amatera Stealer via ClickFix

A fake student resume is being used to place a remote-access tool on researchers’ Windows…

6 hours ago