Cookies are small values stored by a browser that websites use to remember sessions, preferences and limited state, sent with requests to the matching domain. Attributes such as HttpOnly, Secure and SameSite reduce exposure. In the EU, storing or reading them on a device is governed mainly by the ePrivacy Directive, which usually requires consent for anything not strictly necessary.
What browser cookies are and what they do
Cookies are not just “small files.” They are a browser-mediated state mechanism that lets a site recognise a returning user, preserve a login session, and remember settings between requests. Because they are attached to matching domains, they influence how web applications maintain continuity without making every request stateless.
That makes cookies a core web plumbing concept rather than a simple storage feature. They can carry session identifiers, preference flags, anti-CSRF tokens, or other limited state, and their security properties depend heavily on how the application sets scope, lifetime, and delivery rules.
How cookies are sent and scoped
Cookie behaviour is controlled by attributes and matching rules. Domain and path scope decide where a cookie is returned, while expiry controls persistence. Secure limits transmission to HTTPS, HttpOnly blocks client-side script access, and SameSite affects when browsers attach the cookie to cross-site requests.
Those controls matter because a cookie is only useful if the browser can present it at the right time, but that same convenience creates risk if it is sent too broadly. Good scoping reduces accidental leakage to unrelated paths, subdomains, or cross-site contexts.
Security properties and common protections
Most security discussion around cookies centres on protecting the session or other bearer state they contain. If an attacker steals a session cookie, they may be able to act as the user until the session expires or is revoked. That is why cookie attributes such as HttpOnly, Secure and SameSite are treated as baseline hardening rather than optional polish.
Cookie security is also tied to the application’s own session design. A secure cookie does not fix weak session generation, overly long lifetimes, poor logout handling, or reuse across trust boundaries. The browser may enforce transport and script restrictions, but the application still has to treat the cookie as sensitive authentication material.
Privacy, consent and compliance context
Cookies also sit inside a legal and privacy framework, not only a technical one. In the EU, storing or reading non-essential cookies on a device is generally governed by the ePrivacy Directive, which usually requires consent. That is why cookie banners, preference centres and consent records are often part of the implementation, not just the UX.
Practitioners also need to separate operationally necessary cookies from analytics, advertising and other tracking functions. The legal threshold is not simply whether the cookie is technically harmless, but whether it is strictly necessary for the service the user asked for.
Risk and Threat Considerations
Cookies are attractive to attackers because they often function like portable proof of an authenticated session. If they are exposed through script access, insecure transport, cross-site request handling mistakes, or weak session management, an attacker may be able to hijack an active session or replay state without knowing the password.
Failure mechanism: The cookie is stolen, replayed, or attached in an unexpected browser context because confidentiality or request-boundary controls were too weak.
Impact: The attacker can impersonate the user, abuse authorised actions, or prolong access until the session is invalidated.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5 and OWASP ASVS set the technical controls, while GDPR defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Cookies often carry session state that must be rotated and invalidated safely. |
| SC-8 — Transmission Confidentiality and Integrity | Secure cookie transport depends on protecting data in transit with HTTPS. | |
| AC-12 — Session Termination | Cookie sessions need reliable end-of-session invalidation to limit replay risk. | |
| Recommendation — Manage cookie-backed session material with lifecycle controls that support prompt revocation and renewal. Enforce protected transmission so cookies are not exposed on the network. Terminate cookie-backed sessions decisively when the user logs out or the session expires. | ||
| OWASP ASVS | V7 — Session Management | Cookies are the standard browser mechanism for session state and session security. |
| Recommendation — Verify secure session cookie handling, expiry, and invalidation throughout the application. | ||
| GDPR | Art. 5 — Principles relating to processing of personal data | Cookie-based tracking and preference data can implicate lawful, fair, and minimised processing. |
| Recommendation — Limit cookie processing to what is necessary and align it with a valid legal basis. | ||
Practitioner Guidance
Common misunderstanding: A cookie is not automatically safe just because it is “session-only” or hidden from JavaScript. Security depends on whether it is scoped narrowly, protected in transit, and treated as sensitive state on the server side.
What to watch for: Review whether the application sets the right attributes for each cookie, distinguishes essential from non-essential purposes, and avoids persisting more state than it needs. Where cookies carry authentication or preference state, align their handling with the trust boundary they actually cross.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 24, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org