Application Security, Cryptography & Defense in Depth
Treat security as a foundational architectural constraint. Eliminate OWASP Top 10 vulnerabilities (SSRF, BOLA/IDOR, SQLi), enforce memory-hard password hashing (Argon2id), prevent timing attacks with hmac.compare_digest, and harden JWT token issuance.
Senior Systems Studio: Application Security, Cryptography & Defense in Depth
Select any senior topic below to implement SSRF protection with private IP range validation, enforce BOLA/IDOR database query tenant boundaries, verify memory-hard Argon2id/bcrypt password hashing, prevent side-channel timing attacks using hmac.compare_digest, and enforce RS256 asymmetric JWT security.
OWASP Defenses, Constant-Time Comparison & JWT Hardening
- SSRF & BOLA Boundaries: Validate external HTTP URLs by resolving DNS and rejecting private IP ranges (
10.0.0.0/8,127.0.0.0/8,169.254.169.254). Enforce database tenant isolation (WHERE id = :id AND org_id = :user_org_id). - Memory-Hard Hashing: Use Argon2id or bcrypt (cost ≥ 12) for credentials. Never use general-purpose fast hashing functions (MD5, SHA-256) for secret passwords.
- Constant-Time Operations & JWT: Compare secret hashes with
hmac.compare_digestto avoid side-channel timing leaks. Enforce asymmetric JWT signatures (RS256) and reject algorithm"none".
1. SSRF & BOLA Boundary Defenses
Inspect user-provided URLs and enforce database tenant isolation to prevent cloud metadata theft and unauthorized data access:
import ipaddress, socket, urllib.parse
def is_safe_ssrf_url(url: str) -> bool:
parsed = urllib.parse.urlparse(url)
if parsed.scheme != "https":
return False
ip_str = socket.gethostbyname(parsed.hostname)
ip = ipaddress.ip_address(ip_str)
# Reject loopback (127.0.0.0/8), private (10.0.0.0/8, 192.168.0.0/16), and link-local (169.254.169.254)
return not (ip.is_private or ip.is_loopback or ip.is_link_local)
2. Cryptography & Constant-Time Security
Eliminate side-channel timing attacks and configure memory-hard password verification:
import hmac
# Constant-Time Comparison prevents timing attacks (vs '==' short-circuit)
def safe_verify_secret(provided_token: str, expected_token: str) -> bool:
return hmac.compare_digest(provided_token.encode('utf-8'), expected_token.encode('utf-8'))