Stealing HttpOnly cookies with the cookie sandwich technique
Executive Summary
The article describes a technique called the cookie sandwich that exploits legacy cookie parsing rules to bypass the HttpOnly flag on certain servers. By inserting specially crafted quotes and a $Version cookie, an attacker can cause a server to misinterpret the cookie header and expose an HttpOnly session cookie to client‑side scripts. The author demonstrates the attack against a Flask application and a vulnerable site that reflected a tracking domain, showing that the technique can be combined with reflected XSS or CORS misconfigurations to steal PHPSESSID cookies. Defenders should ensure that HttpOnly cookies are set correctly, avoid legacy cookie parsing, and sanitize reflected parameters to prevent XSS.
Original Overview
In this post, I will introduce the "cookie sandwich" technique which lets you bypass the HttpOnly flag on certain servers. This research follows on from Bypassing WAFs with the phantom $Version cookie . Careful readers may have noticed that legacy cookies allow special characters to be included inside the cookie value. In this post, we're going to abuse that. The cookie sandwich technique manipulates how web servers parse and handle cookies when special characters are used within them. By cleverly placing quotes and legacy cookies, an attacker can cause the server to misinterpret the structure of the cookie header, potentially exposing HttpOnly cookies to client-side scripts. Because the Chrome browser doesn't support legacy cookies, it lets attackers create a cookie name that starts...