Choose Secure and HttpOnly cookie settings

  • Secure

    Send the cookie over HTTPS. This attribute alone doesn't prevent scripts from reading it.

  • HttpOnly

    Keep the cookie out of JavaScript cookie APIs.

The cookie reference defines each attribute. Choose them to suit what the cookie does.

A cookie is missing security protections

Choose SameSite cookie settings that keep sign-in working

  • With Strict, the browser sends the cookie only on same-site requests. Lax also sends it on certain top-level cross-site navigations. None allows cross-site sending and requires Secure.

  • Test sign-in, return links and intended embeds before tightening the setting.

Use cookie name prefixes to lock a cookie to one host

  • Omitting Domain makes a cookie host-only. In supporting browsers, the __Host- name prefix requires Secure, Path=/ and no Domain attribute. The __Secure- prefix requires a secure origin and Secure, but doesn't impose that same host-only scope.

  • Where browsers support cookie prefixes, they enforce those extra requirements. Prefixes don't replace the rest of the cookie's configuration.

Frequently asked questions

Does an HttpOnly cookie stop cross-site scripting?

No. HttpOnly keeps page scripts from reading the cookie, but the browser still attaches it to requests those scripts make. Treat script injection as a separate problem.