Cookies · Practical guide
Secure, HttpOnly and SameSite cookies explained
Secure limits a cookie to secure transport, HttpOnly prevents JavaScript from reading it, and SameSite controls its use across sites. Start with the cookie’s purpose, change the application that creates it, then check whether the browser stores, sends and removes it correctly. A public header scan can flag attributes; it cannot complete an authenticated journey for you.
Fix SameSite=None on an embedded session
Suppose a booking widget at widgets.example.net is embedded on shop.example.com. The widget needs a session in that cross-site context, but sends SameSite=None without Secure. Browsers require Secure with None. Fix the widget application that issues the cookie and serve it over HTTPS; changing every cookie on the shop will not repair the widget’s response.
The example below is for a server-managed widget session that JavaScript does not need to read. Its value is a placeholder, and omitting Domain keeps it on the issuing host. A session used while visiting the shop directly can often use Lax instead. None does not override browser restrictions on third-party cookies, so test the embedded flow with those restrictions enabled.
# Before: the cross-site cookie lacks the required Secure flag
Set-Cookie: widget_session=example-value; Path=/; HttpOnly; SameSite=None
# After: issued by the widget application over HTTPS
Set-Cookie: widget_session=example-value; Path=/; Secure; HttpOnly; SameSite=None - Find the response that creates the cookie in DevTools > Network. Record the top-level site, embedded host and later request that needs the session.
- Update the session middleware or cookie API in the application that emits that response. Deploy over HTTPS, and check that a proxy has not replaced the intended attributes.
- Repeat the widget journey and inspect both stored cookies and the next request. The cookie must be accepted and sent where needed; investigate any blocked-cookie reason instead of assuming None guarantees access.
Reference: MDN: third-party cookies and browser restrictions
Choose attributes for the requests your cookie needs
Choose SameSite explicitly instead of depending on a browser default. A session cookie and a preference cookie may have different requirements. HttpOnly is appropriate when JavaScript does not need to read the value; applying it to a cookie intentionally read by your frontend changes that behaviour.
A different origin is not automatically a different site. For example, https://app.example.com and https://api.example.com have different origins but share a site. Cookie Domain rules still determine whether a cookie can reach both hosts. SameSite does not widen its Domain.
Keep application authorization and CSRF protection in place. HttpOnly stops JavaScript from reading the cookie through cookie APIs, but the browser can still send it with JavaScript-initiated requests. These attributes do not prevent every consequence of malicious script.
| Attribute | Effect | Check before deploying |
|---|---|---|
| Secure | Send the cookie over HTTPS, with browser exceptions for localhost. | The production cookie is issued over HTTPS and its required requests use HTTPS. |
| HttpOnly | Prevent JavaScript cookie APIs from reading the value. | The frontend does not need to read this session identifier. |
| SameSite=Strict | Limit transmission to same-site requests. | Arrival from an external link still has the intended login behaviour. |
| SameSite=Lax | Also permit qualifying cross-site top-level navigation with a safe method, such as a normal GET link. | Do not assume a cross-site iframe request or POST callback will carry the cookie. |
| SameSite=None | Allow cross-site use under cookie rules; Secure is required. | Test browser third-party-cookie restrictions and the actual embedded or callback flow. |
Reference: MDN: Set-Cookie
Configure a host-only session in the application
For an HTTPS application whose session belongs only to app.example.com, evaluate the configuration below. Let the framework generate and manage the real session identifier. Set the name, Secure, HttpOnly, SameSite and scope in its session configuration or cookie API; manually editing a browser cookie does not fix the response that creates it.
In supporting browsers, the __Host- prefix requires HTTPS, Secure, Path=/ and no Domain attribute. It does not imply HttpOnly or SameSite: include those separately. The application must read and write the complete prefixed name. Plan a migration before renaming an existing session cookie, since visitors may still hold the old name and may need to sign in again.
Without Domain, a cookie stays on its issuing host. Domain=example.com makes it available to that domain and its subdomains, which should be an intentional requirement. Such a shared-domain session cannot use __Host-. Path controls matching request paths; it is not a security boundary between applications on one host.
Send each cookie in its own Set-Cookie header, without combining them with commas. If a gateway also rewrites cookies, inspect the final response for repeated or conflicting attributes. Test external sign-in and payment returns before adopting Lax for an existing session.
# Example for a host-only session; the value is a placeholder
Set-Cookie: __Host-session=example-value; Path=/; Secure; HttpOnly; SameSite=Lax Reference: MDN: secure cookie configuration
Check browser acceptance as well as response headers
HeaderScan examines Set-Cookie in the final response. It does not sign in, send cookies or run JavaScript. Cookies created on earlier redirects, after authentication or by client-side code may be absent. “No Set-Cookie received” means none was observed on that response; it does not mean the application uses no cookies.
The report checks attributes, not complete browser acceptance. It cannot prove a cookie was stored or attached to a later request, and does not validate cookie-prefix rules or the public suffix list. A passing attribute finding is therefore not evidence that an embedded session works.
In Chrome DevTools, use Application > Storage > Cookies to inspect stored cookies and their scope. Under Network, select the response that sets the cookie and inspect its Cookies tab for warnings. Then inspect the next request that needs the session. Keep session values out of tickets, shared screenshots and copied headers.
| Observation | Where to investigate | Expected result |
|---|---|---|
| Set-Cookie exists, but the cookie is not stored | Response Cookies and blocked-cookie reasons; check Secure, SameSite, Domain and prefix rules. | The browser accepts the live cookie with the intended scope. |
| Cookie is stored, but missing from the next request | Request Cookies; compare the destination host, path, HTTPS and cross-site context. | The intended session request carries the cookie, subject to browser privacy rules. |
| Cookie is sent, but the user is still logged out | Application session handling, expiry and the configured cookie name. | The server recognizes the session and returns the correct account. |
Reference: Chrome DevTools: inspect cookies and blocked reasons
Keep reading
Related guides
HTTP security headers: what to check first
Fix security header findings with CSP examples, a staged HSTS rollout, framing rules and practical browser and curl checks.
Read guide CachingCache-Control explained: no-cache, no-store and private
Choose Cache-Control for account pages, public HTML and versioned assets, then verify ETag revalidation and CDN behaviour with practical checks.
Read guide Nginx configurationHow to configure security headers in Nginx
Add Nginx security headers to the correct HTTPS server, fix location inheritance and duplicates, then verify normal pages and error responses.
Read guide LaravelHow to add security headers in Laravel
Add response headers with Laravel middleware, register them correctly, test normal and error responses, and check proxy or CDN overrides.
Read guide CSP implementationHow to roll out Content Security Policy with Report-Only
Build and test a CSP candidate, connect matching nonces and reporting endpoints, then enforce it with a practical rollback plan.
Read guideHTTP response headers reference: security, cookies and caching
Look up common HTTP response headers, their purpose and the checks to make before changing a policy.
Open reference