Thursday, January 23, 2025
HomeBrowserNew Cookie Sandwich Technique Allows Stealing of HttpOnly Cookies

New Cookie Sandwich Technique Allows Stealing of HttpOnly Cookies

Published on

SIEM as a Service

Follow Us on Google News

The “Cookie Sandwich Attack” showcases a sophisticated way of exploiting inconsistencies in cookie parsing by web servers.

This technique allows attackers to manipulate HTTP cookie headers to expose sensitive session cookies, including those marked with the HttpOnly flag, making it possible to access restricted data through client-side scripts.

By combining legacy cookie standards, special characters, and browser behavior, this attack represents a critical threat to poorly configured web applications.

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

Exploiting Parsing Ambiguities in Cookies

The attack leverages differences in how web servers, frameworks, and browsers handle cookies based on legacy standards such as RFC2109, in contrast to the modern RFC6265 standard.

For example, browsers like Chrome allow JavaScript to create cookies with names prefixed by a $ (e.g., $Version) even though such cookies are not directly supported.

Attackers can define quoted cookie values that create a “sandwich” around sensitive cookies, leading to misinterpretation by the server.

A sample manipulation looks like this:

document.cookie = `$Version=1;`;
document.cookie = `param1="start`;
document.cookie = `param2=end";`;

This results in the following HTTP request header:

GET / HTTP/1.1
Cookie: $Version=1; param1="start; sessionId=secret; param2=end"

When processed by servers like Apache Tomcat, which falls back to legacy parsing logic upon detection, $Version, the entire string, including the sensitive, sessionId can be assigned toparam1.

If this cookie value is reflected in a response without the HttpOnly flag, attackers can extract it using client-side scripts.

Python frameworks, such as Flask, are inherently vulnerable to such attacks due to their support for quoted cookie strings and automatic encoding of special characters.

This enables attackers to bypass traditional cookie parsing safeguards without requiring the $Version attribute.

Combining XSS and Cookie Manipulation

An attack on a vulnerable web application using an analytics tracking domain demonstrated the theft of an HttpOnly PHPSESSID cookie in four stages.

First, attackers exploited a Cross-Site Scripting (XSS) vulnerability by injecting JavaScript via unsanitized attributes, bypassing AWS WAF using an oncontentvisibilityautostatechange event.

Next, they identified that a tracking domain exposed session details in cross-origin JSON responses.

The attackers then manipulated cookie headers, using the $Version attribute and modifying the path to insert a PHPSESSID value in a JSON response, which the Apache Tomcat server reflected back.

Finally, JavaScript was used to automate cookie exfiltration via a CORS request.

According to the Port Swigger, to prevent such attacks, web servers must strictly adhere to RFC6265, disable legacy standards like RFC2109, and ensure proper sanitization and security for cross-origin requests.

Always set the HttpOnly and Secure flags for sensitive cookies such as session cookies to prevent JavaScript access or transmission over insecure connections.

Sanitize user inputs and outputs rigorously, particularly for reflected values in HTTP responses or HTML attributes. Prevent the injection of arbitrary scripts or content.

Restrict cross-origin requests to trusted origins and avoid reflecting sensitive data in responses.

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

Aman Mishra
Aman Mishra
Aman Mishra is a Security and privacy Reporter covering various data breach, cyber crime, malware, & vulnerability.

Latest articles

Critical Vulnerability in Next.js Framework Exposes Websites to Cache Poisoning and XSS Attacks

A new report has put the spotlight on potential security vulnerabilities within the popular...

GhostGPT – Jailbreaked ChatGPT that Creates Malware & Exploits

Artificial intelligence (AI) tools have revolutionized how we approach everyday tasks, but they also...

Tycoon 2FA Phishing Kit Using Specially Crafted Code to Evade Detection

The rapid evolution of Phishing-as-a-Service (PhaaS) platforms is reshaping the threat landscape, enabling attackers...

Nnice Ransomware Attacking Windows Systems With Advanced Encryption Techniques

CYFIRMA's Research and Advisory team has identified a new strain of ransomware labeled "Nnice,"...

API Security Webinar

Free Webinar - DevSecOps Hacks

By embedding security into your CI/CD workflows, you can shift left, streamline your DevSecOps processes, and release secure applications faster—all while saving time and resources.

In this webinar, join Phani Deepak Akella ( VP of Marketing ) and Karthik Krishnamoorthy (CTO), Indusface as they explores best practices for integrating application security into your CI/CD workflows using tools like Jenkins and Jira.

Discussion points

Automate security scans as part of the CI/CD pipeline.
Get real-time, actionable insights into vulnerabilities.
Prioritize and track fixes directly in Jira, enhancing collaboration.
Reduce risks and costs by addressing vulnerabilities pre-production.

More like this

Critical Vulnerability in Next.js Framework Exposes Websites to Cache Poisoning and XSS Attacks

A new report has put the spotlight on potential security vulnerabilities within the popular...

Murdoc Botnet Exploiting AVTECH Cameras & Huawei Routers to Gain Complete Control

Researchers have identified an active malware campaign involving a Mirai botnet variant, dubbed Murdoc,...

New Supply Chain Attack Targeting Chrome Extensions to Inject Malicious Code

A sophisticated supply chain attack targeting Chrome browser extensions has come to light, potentially...