Session Cookies That Carry Nothing
A session cookie is a random token with no data in it. The server stores a hash of the token, and identity lives in the database row the hash finds.
Security
Sessions, OAuth, secrets and access checks that fail closed
13 guides in this collection
A session cookie is a random token with no data in it. The server stores a hash of the token, and identity lives in the database row the hash finds.
A session proves who someone is. What they may do is read from the database on each request, so removing a role takes effect on the next click.
The state value is a signed cookie and a hashed database row. The callback verifies both and consumes the row in one atomic update, so a replay fails.
A limit on failed attempts per email lets anyone lock a victim out. Limit per address first, set the per-email limit much higher, and prove the rule.
API keys kept in a key-value store are sealed with AES-GCM under a per-purpose key, bound to their record, and shown again only as four characters.
The route that creates the first owner is the most dangerous one in a new deploy. Gate it with a bearer secret, lock it after one use, and undo partial writes.
A return-to value must be a path on your own site. Checking for a leading slash is not enough, because browsers read a slash and a backslash as a new host.
A sign-in form with no method submits as GET before JavaScript loads and puts the password in the URL. Declare POST, and prefix credential field names.
Admin screens get shared, recorded and screenshotted. Mask names, emails and addresses on the server by default, and make a reveal explicit, short and logged.
Cron routes and webhooks have no user to sign in. Give each a secret, compare it in constant time with one shared helper, and answer 503 while it is unset.
Binding to 127.0.0.1 keeps other machines out. It does not keep out the web pages open in your own browser, which can post to localhost freely.
A URL that a user or tenant chose can point at your own network. Send it through one fetcher that checks the address at every redirect, with a timeout and a size cap.