Pcornel
Browse topics
Options
Recent
Favorites
Security · Technical reference

Cookies

Direct answer

Cookies store session and state data in the browser. Mark session cookies Secure, HttpOnly and SameSite, scope them to the right domain and path, and give them sensible lifetimes.

When to use this

Use this when setting cookie security attributes.

First 30 seconds

1. Cookies: Secure (HTTPS only), HttpOnly (no JS), SameSite (CSRF), Path/Domain scope.

2. __Host- prefix for strongest scoping.

3. Short lifetime for session cookies.

4. Don't store sensitive data in cookies.

5. Sign/encrypt if needed.

Operational verification

server Set-Cookie → browser stores with flags → sent per rules

Context & applicabilityCommon mistakes · platform/version boundaries
Common mistakes
Common mistakes
  • Session cookies without HttpOnly, readable by XSS.
  • Domain=.example.com sharing cookies with every subdomain, including less trusted ones.
  • Sensitive data stored in cookies in plain text.
  • Very long-lived "remember me" cookies without rotation or server-side revocation.
Platform / version applicability
Security architecture and operations
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformSecurity architecture and operations
Scope / prerequisiteUse this when setting cookie security attributes.
What next?2 suggested next steps
Evidence1
On this pageJump to a specific section
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Set Secure, HttpOnly and SameSite on session cookies.
  • Scope domain and path narrowly.
  • Use sensible lifetimes.
Key checks
  • curl -sI https://<site> | grep -i set-cookie — cookie flags
  • Secure, HttpOnly, SameSite on session cookies — flags
  • __Host- prefix — scoping
ReferenceWhy it matters1 section · depth on demand

Example

Set-Cookie: session=abc123; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=3600
  • Secure: only over HTTPS.
  • HttpOnly: not readable by JavaScript (limits XSS impact).
  • SameSite: limits cross-site sending (CSRF).
  • Avoid a broad Domain= attribute; it shares the cookie with every subdomain.
ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Cookies store small pieces of data in the browser and are sent automatically with requests to the matching site — which is why they carry sessions and why their attributes matter for security.

AttributeEffect
SecureOnly sent over HTTPS
HttpOnlyNot readable by JavaScript (limits XSS theft)
SameSite=Lax/StrictNot sent on most cross-site requests (CSRF defence)
DomainWhich hosts receive it (omit to restrict to exact host)
PathURL path scope
Max-Age/ExpiresLifetime; omit for session cookies
__Host- prefixEnforces Secure, no Domain, Path=/
Set-Cookie: __Host-session=…; Secure; HttpOnly; SameSite=Lax; Path=/

Documented example, not captured output. Inspect cookies in the browser developer tools (Application/Storage tab).

Cookie attributes

AttributePurpose
SecureSent only over HTTPS
HttpOnlyNot readable by JavaScript (XSS)
SameSite=Lax/StrictLimits cross-site sending (CSRF)
Path, DomainScope — avoid broad Domain
Max-Age / ExpiresLifetime; omit for session cookies
__Host- prefixForces Secure, Path=/, no Domain
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docSecurity architecture and operations current

Authoritative/upstream documentation reviewed for bounded claims in Web Security → Cookies. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%
Confirmation

Confirm action

Continue?