One page

Auth and security cheat sheet

What to keep at hand. If a line is not clear, go back to the matching lesson in the course.

Open the course: Auth and security

Sessions and passwords

WhatHow
CookieHttpOnly; Secure; SameSite=Lax
Password hashawait bcrypt.hash(password, 12)
Checkingawait bcrypt.compare(input, hash)

Tokens and defenses

WhatHow
Issue a JWTjwt.sign({ sub: id }, SECRET, { expiresIn: "15m" })
HeaderAuthorization: Bearer <token>
CORScors({ origin: ["https://app.example"], credentials: true })
SQLdb.query("… WHERE email = $1", [email])

Permissions and hardening

WhatHow
Permissioncan(user, "posts:delete")
Random tokenrandomBytes(32).toString("base64url")
Sign in with Googleresponse_type=code&scope=openid email
HTTPS onlyStrict-Transport-Security: max-age=31536000
Script sourcesContent-Security-Policy: default-src 'self'

Other cheat sheets