Issue
HTTP cookies let a browser store values and return them to a site in later requests. A server usually creates or updates a cookie with a Set-Cookie response header. Cookie attributes control when the browser sends the cookie and whether client-side scripts can read it. They do not, by themselves, secure the application’s session handling. RFC 6265, MDN: Set-Cookie
Misconfiguration occurs when a cookie’s scope or protections do not fit its purpose. This matters most for authentication and session cookies, whose values may let a server recognize a logged-in user.
| Attribute | Browser behavior | Common concern |
|---|---|---|
| Secure | Sends the cookie only over secure connections, usually HTTPS. | Without it, a browser may send a session cookie over HTTP if the site is reachable that way. |
| HttpOnly | Prevents browser scripts from reading the cookie through APIs such as document.cookie. | Without it, a script running on the site may be able to read the cookie. This does not prevent that script from making requests as the user. |
| SameSite | Controls whether the cookie accompanies cross-site requests. Strict is most restrictive; Lax permits some top-level navigations; None allows cross-site use and requires Secure in supporting browsers. | An overly permissive setting can remove a layer of protection against some cross-site request forgery (CSRF) attacks. A restrictive setting can also disrupt legitimate sign-in or embedded workflows. |
| Domain | Makes a cookie available to the specified domain and its subdomains. Omitting it makes the cookie host-only. | A broader domain can expose the cookie to more subdomains, including less trusted ones. |
| Path | Limits which request paths receive the cookie. | It is a routing scope, not a reliable security boundary between applications on the same host. |
These behaviors are defined by cookie standards and browser documentation. SameSite is a defense-in-depth measure: it does not replace CSRF tokens or other appropriate request validation. HttpOnly limits script access to a cookie’s value but does not stop an injected script from using the victim’s authenticated browser session. MDN: secure cookie configuration, OWASP Session Management Cheat Sheet, OWASP CSRF Prevention Cheat Sheet
Common causes include incomplete framework defaults, inconsistent settings across login and session-renewal responses, a cookie shared across subdomains without need, or changing SameSite to None to make a cross-site flow work without evaluating the security consequences.
Examples
Example: session cookie with common protections
Set-Cookie: __Host-SessionID=dummy-session-value; Path=/; Secure; HttpOnly; SameSite=Lax
This sets a host-only cookie because there is no Domain attribute. The __Host- prefix requires Secure, Path=/, and no Domain attribute in supporting browsers. Lax is often a practical choice, but the right SameSite setting depends on the application’s flows. Strict may interfere with some sign-in or navigation flows; None should be used only when cross-site cookie use is needed and must be paired with Secure. MDN: cookie prefixes, OWASP Session Management Cheat Sheet
Example: cross-site cookie for a required integration
Set-Cookie: IntegrationState=dummy-state; Path=/; Secure; HttpOnly; SameSite=None
Use this pattern only when the cookie must be sent in cross-site contexts. Confirm that the target browsers accept it and that the server has appropriate protections for state-changing requests. Browser privacy settings may restrict cross-site cookies even when the header is configured this way.
Example: inspect a response header
curl -sS -D - -o /dev/null https://app.example.com/login
This can display response headers, including Set-Cookie, for that request. It does not prove that a browser will store or send the cookie in every context, or that a vulnerability is exploitable.
Impact
Impact depends on the cookie’s purpose and the behavior that can be demonstrated:
- If an authentication cookie is sent over HTTP, someone able to observe that unencrypted traffic may be able to obtain the cookie and attempt to reuse it. The risk depends on whether HTTP is reachable, whether the cookie is actually sent there, and whether the server accepts the session.
- If a session cookie lacks HttpOnly, a script execution flaw may be able to read its value. The missing attribute alone does not prove that an attacker can execute script or take over an account.
- If a cookie is sent in cross-site requests, a separate weakness that lets an attacker trigger a state-changing request may enable CSRF. A permissive SameSite setting alone does not prove that a sensitive action is exploitable.
- If a cookie’s Domain is broader than necessary, more subdomains can receive it. Exploitation depends on the trust and security of those subdomains and on how the server validates the cookie.
- A Path setting does not isolate applications from one another as a security control.
Do not infer data theft, authentication bypass, or account takeover from a missing attribute alone. Confirm the cookie’s role and show the relevant browser and server behavior before making those claims. OWASP WSTG: Testing for Cookies Attributes
Testing
1. Check session cookies for exposure and scope
Inspect session cookies in browser developer tools. Review Secure, HttpOnly, Domain, and Path against how the cookie is used, then check the actual browser behavior.
Example: A missing HttpOnly attribute allows JavaScript access to that cookie. It does not by itself establish that script execution is possible.
GET /login HTTP/1.1
Host: app.example.test
2. Check SameSite and cross-site behavior
Review SameSite on relevant cookies and test supported browser flows from a separate origin. Observe whether the cookie is sent and whether server-side request protections are present.
Example: SameSite affects when the browser sends cookies. A particular setting alone does not prove CSRF.
GET /account HTTP/1.1
Host: app.example.test
Cookie: session=TEST_SESSION
3. Check lifetime and replacement
Review expiry and session invalidation on login, logout, and credential changes. Confirm whether an old test cookie remains accepted.
Example: A cookie can remain in the browser after logout. Test the server’s acceptance of its value.
A browser’s cookie panel can show stored attributes, but it does not prove how every request behaves. A command-line client that prints Set-Cookie headers is useful for inspecting responses, but it does not reproduce browser enforcement of SameSite or script access rules. OWASP’s testing guide recommends reviewing both response headers and the browser’s cookie jar. OWASP WSTG
Common false positives: A cookie without HttpOnly may intentionally be readable by application code, such as a CSRF token designed for a particular client-side pattern. A cross-site cookie may be required for a documented integration. A cookie visible in a response is not necessarily an authentication cookie. Evaluate the cookie’s function and the complete request flow before classifying a finding.
Mitigation
Primary fixes
- Set Secure on authentication and session cookies, and serve the application over HTTPS. Redirect HTTP traffic to HTTPS and verify that authenticated flows do not send the session cookie over HTTP.
- Set HttpOnly on cookies that client-side scripts do not need to read. Retest any client functionality that depends on direct access; this attribute reduces cookie theft opportunities but does not fix cross-site scripting (XSS).
- Set an explicit SameSite value appropriate to the application. Prefer Lax or Strict where the flow permits. If cross-site use is required, use SameSite=None; Secure and add suitable CSRF defenses.
- Omit Domain unless sharing with subdomains is necessary. If sharing is required, use the narrowest workable domain and assess the security of every included subdomain.
- Use Path to control routine cookie delivery, not to separate security boundaries. Use separate hosts or stronger server-side authorization boundaries when applications require isolation.
- Consider a __Host- name for a session cookie when host-only scope and Path=/ fit the application. Verify browser support for the prefix requirements.
Additional defenses
- Keep session identifiers opaque, unpredictable, and free of personal data. Limit session lifetime according to the application’s needs, and invalidate sessions server-side on logout or other required security events. NIST SP 800-63B: Session Management
- Retain CSRF tokens or other appropriate request validation for state-changing actions. Do not rely on SameSite as the only CSRF defense.
- Review every code path that sets or refreshes a cookie, including reverse proxies and application frameworks, so security attributes remain consistent.
Retest: Repeat the response-header inspection and browser tests for login, renewal, logout, and relevant cross-site flows. Confirm that the browser applies the intended scope and attributes, that HTTP requests do not carry the protected session cookie, and that legitimate workflows still function. A configuration change is evidence of remediation; it does not establish that unrelated session, XSS, or CSRF weaknesses are absent.