THE TAKEAWAYS
What to take away
- Omitting Domain makes a cookie host-only. Do not set it unless you need to share with subdomains.
- HttpOnly blocks JavaScript from reading a cookie but does not stop the cookie from being sent.
- SameSite decides how cookies attach to cross-site requests. None requires Secure.
- Regenerate the session on every sign-in and keep cookies for sensitive data short-lived.
- The __Host- prefix makes browsers enforce Secure, Path=/ and no Domain.
FROM PRIMARY SOURCES
Cookie safety is decided by attributes
MDN's cookie guide lists session management, such as sign-in status or cart contents the server needs to remember, as one of the main uses of cookies. Sign-in features commonly put a server-issued session identifier in a cookie that the browser sends with every later request. If someone else learns that identifier, they may be able to impersonate the user.
The basic rule is to make the value a sufficiently long, unguessable identifier. That is not enough on its own, because the same value can be sent to very different scopes and read through different routes depending on the attributes in the Set-Cookie header. Domain, Path, Secure, HttpOnly, SameSite, Expires and Max-Age each address a different problem. No single attribute protects everything.
MDN suggests that, depending on the application, you may want to use an opaque identifier that the server looks up rather than storing sensitive information directly in cookies. Do not put names, permissions or email addresses directly in the cookie; put only a key to look up the server-side record. Deciding this first clarifies what the attribute design must protect.
Operationally, the problem is when attribute values stay at framework or library defaults and nobody can explain the intent. Defaults may also change with version updates. Record which value each attribute takes and why in the design document, and confirm it in real responses. This article looks at those decisions attribute by attribute.
FROM PRIMARY SOURCES
Scope: Domain and Path
The first decision is which hosts receive the cookie. According to MDN, if Domain is omitted, the cookie is returned only to the host that sent it, becoming a host-only cookie, which is more restrictive than naming the host explicitly. If Domain is set, the cookie becomes available to that domain and all its subdomains. Once set, subdomains are always included.
For example, if the sign-in page is on app.example.com and you set Domain=example.com, the session cookie is also sent to www.example.com, campaign subdomains and aliases run by other companies. A single vulnerable page or suspicious script among them becomes a route for leaking the session identifier. Unless there is a clear reason to share sign-in across subdomains, it is safer not to set Domain.
The Path attribute decides whether the cookie is sent based on the path of the requested URL. But MDN states that Path is not intended as a security measure and does not protect against reading the cookie from a different path. Assuming that limiting an admin cookie to /admin keeps other pages from reading it is wrong. To narrow scope, rely on omitting Domain and separating hosts, not on Path.
For scope design, a list of the hosts under your domain and who runs them helps. Decide which hosts share the session cookie and configure everything else not to receive it. When creating a new subdomain, have a step that checks this list to see whether it falls within an existing cookie's scope.
Sources: [1]
FROM PRIMARY SOURCES
Reading and sending routes: Secure and HttpOnly
With Secure, the cookie is sent to the server only on https requests. MDN explains that this makes it more resistant to manipulator-in-the-middle attacks. It is a must for sign-in cookies. MDN also notes that insecure http sites cannot set cookies with the Secure attribute, so pages not yet moved to HTTPS behave differently here.
However, MDN warns not to assume that Secure prevents all access to sensitive information in cookies. Values can still be read or modified with access to the device's storage, or from JavaScript if HttpOnly is not set. Secure protects the network route, not the device or the page.
HttpOnly forbids JavaScript from accessing the cookie, for example through Document.cookie. MDN explains that this mitigates cross-site scripting. Even if a malicious script gets into a page, it reduces the risk of the session identifier being read and sent out. Sign-in cookies normally do not need to be read by JavaScript, so set it by default.
Note that HttpOnly does not stop the cookie from being sent. MDN says cookies created with HttpOnly are still sent with JavaScript-initiated requests such as fetch(). A malicious script that cannot read the identifier can still send requests as the signed-in user. HttpOnly is part of script defence, to be combined with input handling, output escaping and restricting where content is loaded from.
FROM PRIMARY SOURCES
Requests from other sites: SameSite
SameSite decides whether a cookie is attached to requests that start on other sites. MDN explains that this provides some protection against certain cross-site attacks, including cross-site request forgery (CSRF). Here a site is judged by the registrable domain and the scheme, so other subdomains of the same domain count as the same site.
There are three values. Strict sends the cookie only for requests originating from the same site that set it. Lax also sends it for cross-site top-level navigations, such as following a link, that use safe methods, which excludes POST. None sends it on cross-site requests too, and then the Secure attribute must also be set.
MDN notes that some browsers use Lax as the default when SameSite is not specified, and that the default Lax can be more permissive, for example including cookies in POST requests shortly after they were set. Relying on the default means accepting different behaviour across browsers. Set the value explicitly on sign-in cookies.
Which value to choose depends on how the service is used. Lax is easy if you want links from external sites to open signed-in pages; Strict can be considered for cookies limited to payment or settings screens. Uses that need None, such as components embedded in other companies' sites, are limited. If you use None, record the reason and impact and combine it with other defences such as CSRF tokens.
EDITORIAL PRACTICE
How long it lasts: expiry and regenerating sessions
A cookie without Expires or Max-Age is a session cookie and is said to be removed when the browser closes. MDN warns, however, that many browsers restore tabs and may restore session cookies as if the browser had never closed. The cookie guide also says session restoring can cause session cookies to last indefinitely.
So the assumption that closing the browser signs the user out does not hold. The length of a sign-in must be managed by the server-side session expiry as well as the cookie's. Invalidate the session on the server after a period of inactivity so that a lingering cookie cannot be used. On sign-out, do not just delete the cookie; reliably invalidate the server-side record.
There are rules for expiry too. According to MDN, Max-Age is the number of seconds until expiry, and zero or a negative number expires the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence. The cookie guide says cookies used for sensitive information should also have a short lifetime. Keep information you want to retain long separately from the sign-in identifier, with its own expiry.
Another important point is regenerating the session on each sign-in. MDN says a site that authenticates users should regenerate and resend session cookies, even existing ones, whenever a user authenticates. This prevents session fixation, where a third party gets a user to use a session it prepared and then takes it over. Do not keep using an identifier issued before sign-in after sign-in.
FROM PRIMARY SOURCES
Use prefixes to catch configuration mistakes
Cookie name prefixes help prevent missing attributes. According to MDN, cookies whose names start with __Secure- must be set with the Secure attribute by a secure HTTPS page. Cookies starting with __Host- must additionally have no Domain attribute and a Path of /. Cookies that do not meet these conditions are rejected by supporting browsers.
MDN explains that the __Host- prefix guarantees the cookie is sent only to the host that set it and not to other hosts on the domain. If a sign-in session cookie carries this prefix and someone later adds Domain by mistake, the cookie is not silently sent more widely; the setting fails and you notice.
MDN also lists the __Http- and __Host-Http- prefixes, which require HttpOnly in addition to Secure to show that the cookie was set through the Set-Cookie header and not from JavaScript. Check browser support before using newer prefixes. Browsers without support do not enforce the constraints, so setting the attributes themselves correctly remains a prerequisite.
When introducing prefixes, note that the cookie name changes. Existing users keep cookies under the old name, so during migration you need to read both names and reissue under the new one. Delete old-name cookies by setting their expiry in the past or Max-Age to 0. Decide the migration steps and when to stop handling the old name in advance.
Sources: [1]
EDITORIAL PRACTICE
Confirm in real responses
Once the attribute design is settled, confirm that the design document matches real responses. Record the Set-Cookie headers for each event that issues or deletes cookies, such as sign-in, sign-out, password change and permission switching. Do not just read framework configuration; fetch responses through the same route as production.
Also check whether intermediate layers such as CDNs, load balancers or authentication proxies rewrite cookies or add others. Especially where authentication is delegated to an external service, cookies issued by that service mix with those issued by your own application. Keep a list of which cookie exists for what purpose and who manages it.
MDN notes that cookies with a Domain that breaks the rules are ignored. A mistake does not raise an error; the cookie is simply not stored and only symptoms appear, such as being unable to sign in or being signed out immediately. To make causes easier to find when enquiries arrive, document a procedure that checks both the attributes issued and the cookies the browser stored.
Keep check results with the change log. Repeat the same checks when you update frameworks or libraries, change CDN settings or change the domain structure. Treat attributes not as something decided once but as something that can break whenever the surrounding configuration changes.
Sources: [1]
EDITORIAL PRACTICE
Design conditions to hand over when delegating
When delegating development or changes of sign-in features to an external developer or an overseas team, do not leave cookie attributes to them; hand them over as conditions. For example, write into the acceptance criteria that the session cookie is host-only without Domain, always has Secure and HttpOnly, the SameSite value and its reason, the cookie expiry and server-side session expiry, and that the session is regenerated on sign-in.
At acceptance, do not just accept a report that conditions are met; receive records of real responses as deliverables. Make it possible to confirm from records that identifiers change before and after sign-in and that old identifiers cannot be used after sign-out. Listing these checks the same way each time keeps the criteria stable when staff change.
Cookie attributes do not appear on screen, so problems tend to go unnoticed until something happens. That is why being able to explain in words what each attribute protects determines the quality of operations. Simply reviewing the design document from the five angles of scope, reading, cross-site, expiry and prefixes catches most oversights in advance.
WITH OPERUN.
Delegate everyday AI management.
The safety of sign-in cookies depends on the combination of attributes, not only on how values are generated. Make them host-only without Domain, protect routes and reading with Secure and HttpOnly, set SameSite explicitly, keep cookie expiry and server-side sessions short, and regenerate on every sign-in. Use the __Host- prefix so mistakes are noticed, and record real responses to confirm. With this order kept in the design and check procedures, protection holds even as the configuration changes.
Discuss your product and AI workPrimary sources
Sources checked on 17 November 2026. The workflows and checklists are editorial proposals.
Share this insight
