SameSite

noun

say it: “SAYM SYTE” /seɪm saɪt/

A cookie setting that tells the browser whether to send the cookie on requests that start on other sites; Lax leaves it off most of them.

What does the SameSite cookie flag do?

SameSite is a cookie flag that tells the browser whether to send the cookie on requests another site starts. SameSite=Lax leaves it off most of them, such as a hidden form on a stranger's page that posts to your site, so that form can't act as your signed-in user.

from fastapi import Response

response = Response()
response.set_cookie("session", "XNh16R", httponly=True, secure=True, samesite="lax")
print(response.headers["set-cookie"])   # session=XNh16R; HttpOnly; Path=/; SameSite=lax; Secure

In a sentence

  • “The session cookie is HttpOnly, Secure and SameSite=Lax.”
  • “With SameSite set to lax, a hidden form on another site can't post to the club API as Maya.”

Level: Journeyman · More Web Development terms at this level

Updated