Hash functions produce fixed-length digests from arbitrary input. Cryptographic hash functions are one-way and collision-resistant, used for integrity verification and password storage.
SHA-256/SHA-512
Secure for integrity checks, digital signatures, TLS
Argon2id
Winner of Password Hashing Competition, OWASP recommended 2023
bcrypt
Time-tested, but limited to 72-byte passwords
PBKDF2
NIST-approved, mandatory for FIPS compliance
Never use MD5 or SHA-1 for security — trivially broken. Use SHA-256 minimum for integrity, Argon2id for passwords.
Use constant-time comparison functions when comparing hash digests — timing attacks can recover secrets from variable-time comparisons even over a network.
PKI uses asymmetric cryptography to establish trust, encrypt communications, and verify identities via certificates signed by trusted Certificate Authorities.
Certificates bind a public key to an identity with CA signature:
Certificate Components: - Subject: CN=api.example.com - Issuer: CN=Let's Encrypt Authority X3 - Public Key: RSA 2048-bit or ECDSA P-256 - Validity: Not Before / Not After - Signature: CA's digital signature - Extensions: SAN (Subject Alternative Names)
Integrate OWASP ZAP or Semgrep into CI pipelines for automated security scanning — fixing vulnerabilities during development is 10x cheaper than post-deployment.
JWT validation: verify signature, issuer, audience, expiry — never skip any check.
// JWT validation (must check ALL fields)import jwt from 'jsonwebtoken';const payload = jwt.verify(token, publicKey, { algorithms: ['RS256'], // asymmetric only, never HS256 for multi-service issuer: 'https://auth.example.com', audience: 'api.example.com', // throws if invalid, expired, wrong issuer/audience});// Never use HS256 (symmetric) for distributed systems// Use RS256 (asymmetric) so services don't need the signing key
res.cookie('access_token', token, { httpOnly: true, // Not accessible to JavaScript secure: true, // HTTPS only sameSite: 'strict', // CSRF protection maxAge: 3600000 // 1 hour});
// VULNERABLE to XSS attackslocalStorage.setItem('access_token', token);// If you must use localStorage (SPA):// - Use short-lived access tokens (5-15 min)// - Implement token refresh flow// - Enable strict CSP
Never store JWTs in localStorage — use HttpOnly cookies with SameSite=Strict for browser auth. If you must use localStorage (SPA), use short-lived access tokens.
☐ All database queries use parameterized statements☐ Authentication endpoints have rate limiting☐ TLS 1.2+ only, TLS 1.3 preferred☐ Security headers configured (CSP, HSTS, X-Frame-Options)☐ Input validation on all API endpoints☐ Secrets stored in secret manager, not environment variables☐ OWASP ZAP/Semgrep integrated in CI pipeline☐ Regular dependency updates (Dependabot/Renovate)☐ Principle of least privilege applied to all service accounts☐ mTLS for service-to-service communication