One page

Web application 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: Web application security

Injection

WhatHow
SQL with a valuepool.query("... WHERE id = $1", [id])
Column or sort orderallowlist, not a placeholder
Prisma, raw SQL$queryRaw`...${x}`, not $queryRawUnsafe
External programexecFile("cmd", [arg]), not exec
MongoDB filtertypeof value === "string"

XSS and CSRF

WhatHow
Output texttextContent, not innerHTML
HTML is requiredDOMPurify.sanitize(html)
CSPscript-src 'nonce-...' 'strict-dynamic'; object-src 'none'
Session cookieHttpOnly; Secure; SameSite=Lax
State changing formCSRF token + Origin check

Authentication and secrets

WhatHow
Password hashArgon2id: 19 MiB, t=2, p=1
Comparing secretscrypto.timingSafeEqual(a, b)
Login limitper account and per IP
Best second factorpasskey (WebAuthn)
A secret leakedrevoke, issue a new one, check the logs
JWT key rotationkid in the header, two keys during the transition

Headers, SSRF, dependencies

WhatHow
HTTPS onlyStrict-Transport-Security: max-age=63072000
Do not guess the typeX-Content-Type-Options: nosniff
No iframesframe-ancestors 'none'
CORS with cookiesOrigin allowlist + Vary: Origin
URL from the userhost allowlist, no redirects
Install in CIpnpm install --frozen-lockfile