OWASP Top 10 overview
Common web risks: injection, broken auth, sensitive data exposure, XXE, broken access control, security misconfiguration, XSS, insecure deserialization, using components with known vulnerabilities, insufficient logging & monitoring.
- Prioritize fixes based on risk and exploitability
- Adopt secure defaults and defense-in-depth
Authentication vs Authorization
Authentication verifies who you are (login); authorization decides what you can do (permissions/roles). Always check authorization on the server.
JWT vs Server Sessions
JWT: stateless tokens signed by server; quick to scale; must manage expiration/rotation and avoid storing sensitive data. Sessions: state kept server-side; simple to revoke; requires shared store for scale.
// Express cookie-session
app.use(session({ secret: process.env.SESSION_SECRET, cookie: { httpOnly: true, secure: true } }));XSS vs CSRF
XSS injects scripts into pages viewed by users; prevent via escaping, CSP, and input sanitization. CSRF tricks a logged-in user to perform actions; prevent via same-site cookies and CSRF tokens.
CORS fundamentals
Cross-Origin Resource Sharing allows browsers to request resources from different origins. Safely configure allowed origins/methods/headers; avoid wildcard on credentials.
// Express CORS (example)
import cors from 'cors';
app.use(cors({ origin: 'https://example.com', methods: ['GET','POST'], credentials: true }));Hashing, salting, and key derivation
Store passwords using slow, salted hashes (bcrypt, scrypt, Argon2). Never store plain hashes without salt. Use HKDF/PBKDF2 for key derivation.
// bcrypt example import bcrypt from 'bcryptjs'; const hash = await bcrypt.hash(password, 12); const ok = await bcrypt.compare(input, hash);
HTTPS/TLS basics
TLS encrypts data in transit using certificates issued by CAs. Keep protocols/ciphers modern, enable HSTS, and rotate certificates automatically.
Preventing SQL Injection
Use parameterized queries/ORM, validate inputs, and least-privilege DB users. Avoid string concatenation to build queries.
// Parameterized query
await db.query('SELECT * FROM users WHERE email = $1', [email]);OWASP Top 10 overview
Common risks like injection, broken auth, sensitive data exposure, XXE, XSS, security misconfigurations, etc.; prioritize mitigations accordingly.
Authentication vs Authorization
Authn verifies who you are; authz defines what you can do. Implement with RBAC/ABAC and least privilege.
JWT pitfalls
Avoid long-lived tokens; use aud/iss claims, rotate secrets, reject none alg, and minimize payload PII.
XSS and CSRF mitigation
Escape user input, use Content Security Policy, SameSite cookies and CSRF tokens; prefer HTTP-only cookies for session storage.
Secrets management
Store secrets in vaults/KMS, never in code; rotate regularly and restrict access via IAM policies.
SAST vs DAST
SAST scans source for vulnerabilities; DAST tests running apps externally. Use both in CI with SBOM for supply chain security.