HttpOnly vs SameSite
People think HttpOnly stops forged requests, and it does not. HttpOnly hides a cookie from scripts on the page, so an XSS script cannot steal the login. The browser still sends the cookie everywhere it goes. SameSite decides where the cookie goes. It keeps the cookie off requests that start on other sites, which is what stops CSRF. A login cookie wants both.
HttpOnly Cookie
A cookie setting. Scripts on the page can never read the cookie.
HttpOnly is a setting on a cookie that hides it from scripts on the page. The browser still sends the cookie with each request to its site. But code in the page cannot read it. So if an attacker gets a script onto the page through XSS, it cannot steal the login cookie. Login cookies should always carry it, along with Secure.
SameSite Cookie Attribute
A cookie setting. It keeps the cookie off requests that start on other sites.
SameSite is a setting on a cookie that says when the browser may send it. A request that starts on another site can leave the cookie behind. Lax keeps it off forms and hidden requests from other sites, but sends it when you click a link. Strict keeps it off every request that starts on another site. None always sends it, and then the cookie must be Secure.
In one line
- HttpOnly Cookie
- A cookie setting. Scripts on the page can never read the cookie.
- SameSite Cookie Attribute
- A cookie setting. It keeps the cookie off requests that start on other sites.