Audience: Infra/SRE/Security, Frontend
βOutcomes: Downgrade-proof TLS, strict origins, no script abuse
TLS & HSTS
import helmet from 'helmet'; app.use(helmet.hsts({ maxAge:31536000, includeSubDomains:true, preload:true })); // TLS 1.2+
CORS (allowlist + credentials)
const allowed = ['https://app.example.com','https://dashboard.example.com']; app.use((req,res,next)=>{ const o = req.header('Origin')||''; if(allowed.includes(o)){ res.header('Access-Control-Allow-Origin', o); res.header('Access-Control-Allow-Credentials', 'true'); res.header('Vary','Origin'); } next(); });
CSP (Helmet)
app.use(helmet.contentSecurityPolicy({ directives:{ defaultSrc:["'self'"], scriptSrc:["'self'","https://js.stripe.com"], connectSrc:["'self'","https://api.stripe.com"], frameSrc:["'self'","https://checkout.stripe.com"], imgSrc:["'self'","data:"], objectSrc:["'none'"], baseUri:["'self'"], frameAncestors:["'none'"] } }));
Isolation
Every DB query includes orgId predicate.
Cross-org actions require partner link + consent.
QA checklist
No wildcard CORS with credentials.
CSP Report-Only passes β then enforce.
Attempt to fetch foreign org resource returns 403.
Runbook: CSP breaks UI
Switch to Report-Only;
Inspect violations;
Add the minimal domains;
Re-enable enforcement.