Safeguard
Security Guides•

Which cookie settings protect store sessions and carts?

Secure, HttpOnly and SameSite settings limit session theft and cross site abuse on a store. What each does and how to check your own cookies.

Safeguard Security Team
3 min read

Set Secure, HttpOnly and SameSite on session cookies, give them the shortest useful lifetime, and scope them to the narrowest domain and path. These settings reduce session theft through cross site scripting and limit cross site request abuse on carts and accounts.

What each attribute does

MDN's guidance on secure cookie configuration says to limit access to cookies as much as possible, because cookies often carry session identifiers or other sensitive information. Its recommendations:

AttributeWhat it does
SecureCookie is sent only over HTTPS
HttpOnlyHides the cookie from JavaScript, which helps stop an XSS bug from stealing a session ID
SameSite Strict or LaxLimits sending the cookie on requests from other sites, a partial defense against CSRF, clickjacking and some cross site leaks
Expires or Max-AgeCookies should expire as soon as no longer needed
DomainUse the most restrictive domain possible
PathUse the most restrictive path possible

The MDN page says to set HttpOnly on all cookies that do not need JavaScript access, and in particular on session identifier cookies.

Why it matters for a store

A session cookie is the key to a logged in account with saved addresses and order history. A cart cookie tied to a session can be abused if another site can trigger requests on a buyer's behalf. If third party scripts run on your pages, an HttpOnly session cookie is a barrier they cannot read directly.

Steps to check your cookies

  1. Open your store in a private browser window, sign in, and open the browser's storage tool.
  2. List cookies for your domain and note which are session, cart, preference and tracking cookies.
  3. For each session or login cookie, confirm Secure, HttpOnly and SameSite are present.
  4. Check that no sensitive value, such as a plain customer ID or email, sits in a cookie readable by scripts.
  5. Check lifetimes. A login cookie that lasts a year deserves a second look.
  6. Set the attributes in your platform or server configuration, then test again after the change.

Limits to remember

SameSite is described as a partial defense, so keep other controls such as anti forgery tokens on state changing requests. HttpOnly stops direct reading, but a script running on the page can still make requests as the user, so it does not replace fixing XSS.

Quick check

Does HttpOnly stop all XSS damage?

No. It prevents reading the cookie from JavaScript, but injected script can still act within the page.

Should every cookie be HttpOnly?

Set it on all cookies that do not need JavaScript access, per MDN. Some preference cookies may need script access.

Sources

Safeguard's DAST scanning can check web apps you own for common misconfigurations, and the free scan is at gold.safeguard.sh/scan.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.