Cookie Attributes

Cookie attributes control how cookies behave: when they're sent, where they're accessible, and how long they last.

Domain Attribute

Purpose: Specifies which domains can access the cookie

Behavior:

Examples:

Set-Cookie: user=john; Domain=example.com

This cookie is accessible by:

Important Notes:

Testing: Use the Parent-Subdomain Test pages to experiment.

Path Attribute

Purpose: Restricts cookie to specific URL paths

Behavior:

Examples:

Set-Cookie: cart=items; Path=/shop

This cookie is sent with:

SameSite Attribute

Purpose: Controls when cookies are sent in cross-site requests

Values:

Understanding Top-Level Navigation

Top-level navigation refers to navigation that changes the browser's main window/tab URL. This includes:

✅ Examples of Top-Level Navigation (SameSite=Lax cookies ARE sent):

❌ Examples of NON-Top-Level Navigation (SameSite=Lax cookies are NOT sent):

Key Distinction: Top-level navigation changes the URL bar. Non-top-level requests are "sub-resource" requests that don't change the visible URL.

Examples:

Set-Cookie: session=abc; SameSite=Strict
Set-Cookie: tracking=xyz; SameSite=None; Secure

Impact on Third-Party Cookies:

Secure Attribute

Purpose: Ensures cookie is only sent over HTTPS

Behavior:

Example:

Set-Cookie: session=abc; Secure

Note: Secure is required when SameSite=None

HttpOnly Attribute

Purpose: Prevents JavaScript access to the cookie

Behavior:

Example:

Set-Cookie: session=abc; HttpOnly

Security Benefit: Protects cookies from XSS (Cross-Site Scripting) attacks

Expires and Max-Age

Purpose: Control when the cookie expires

Expires:

Max-Age:

Session Cookies:

Examples:

Set-Cookie: preference=dark; Expires=Wed, 21 Oct 2025 07:28:00 GMT
Set-Cookie: preference=dark; Max-Age=3600

Combining Attributes

Example:

Set-Cookie: session=abc123; Domain=example.com; Path=/; Secure; HttpOnly; SameSite=Strict; Max-Age=3600

This creates a cookie that:

Testing Attributes

Use the playground to test each attribute:

  1. Main Playground
  2. Cookie Attributes Testing

Observe HTTP request/response headers to see how attributes affect cookie behavior.

Next Steps