Cookies are used for session management, authentication, tracking, and user preferences in web applications. Secure cookies rely on attributes to protect against attacks like XSS, CSRF, and session hijacking.
Hereβs a detailed list of all cookie attributes, their purpose, and how attackers can bypass them. π¨
What It Does?
Set-Cookie: session=abc123; Secure
β οΈ Bypass Techniques
sslstrip
intercept HTTPS β HTTP downgrades, exposing cookies.Secure
isnβt enforced strictly, the cookie might be leaked via insecure HTTP.π‘ Mitigation:
HSTS (Strict-Transport-Security)
to force HTTPS.What It Does?
document.cookie
) from accessing the cookie.Set-Cookie: auth=xyz789; HttpOnly
β οΈ Bypass Techniques
fetch('/account', {credentials: 'include'})
π‘ Mitigation:
What It Does?
Set-Cookie: csrf=abc123; SameSite=Strict
π Modes & Their Security
What It Does?
Set-Cookie: user=John; Domain=.example.com
What It Does?
Set-Cookie: session=xyz123; Path=/admin
What It Does?
Set-Cookie: session=abc123; Max-Age=3600; Expires=Tue, 15 Mar 2025 12:00:00 GMT
What It Does?
Set-Cookie: session=xyz123; Priority=High
Attribute | Purpose | Bypass Method | Mitigation |
---|---|---|---|
Secure | Forces HTTPS-only cookies | SSL Stripping, HTTP Downgrade | HSTS, force HTTPS |
HttpOnly | Blocks JS access | Header-based attacks, XSS | XSS prevention |
SameSite | Prevents CSRF | Open redirects, XS-Leaks | Use Strict mode |
Domain | Controls subdomain access | Subdomain takeover | Avoid Domain unless needed |
Path | Limits cookie access | Path traversal | Restrict Path scope |
Expiry | Sets cookie lifetime | Session fixation | Use HttpOnly for sessions |
π₯ Security Tip: Always use Secure, HttpOnly, and SameSite together for strong security. π