cookie security
1 article
Cookie security is the set of settings and habits that stop the small pieces of data a website stores in a browser from being stolen or misused. Cookies often carry the identifier that keeps a person logged in, which makes them an attractive target.
A cookie is sent by a server, saved by the browser and returned with later requests to the same site. Several attributes control how it behaves. Secure tells the browser to send the cookie only over an encrypted connection. HttpOnly hides it from scripts running in the page, which blunts attacks that inject malicious code. SameSite limits whether the cookie goes along with requests started by other sites, a defence against forged requests. Domain and Path settings narrow where the cookie is sent, and an expiry time limits how long it lives.
Good practice goes beyond attributes. Sensitive values should not be stored in a cookie in readable form, session identifiers should be long and random, and a new identifier should be issued when a user signs in. Cookies also raise privacy questions, since third-party cookies have long been used to follow people across sites, and many laws require consent before non-essential ones are set.
Getting this right matters to anyone who signs in to anything. A cookie left readable by scripts or sent over an open connection can hand an attacker a working login. A few correctly set attributes close off whole classes of attack at almost no cost.