Frontend Security Threat Model
Threat-model SPAs: assets, attackers, XSS/CSRF/supply-chain, and where frontend controls actually land.
- security
- threat-model
- xss
- csrf
- spa
A threat model answers: what are we protecting, from whom, and which controls matter? Frontend interviews often dump buzzwords; seniors map threats to concrete sinks and headers.
Docs: OWASP Threat Modeling, web.dev security, XSS.
Assets
| Asset | Why it matters |
|---|---|
| Session / tokens | Account takeover |
| PII on screen / in memory | Privacy, compliance |
| Actions (transfer, delete) | Fraud |
| Integrity of UI | Phishing inside your origin |
| Admin tools | Privilege abuse |
Attackers & capabilities
- Remote web attacker — hosts evil.com, phishes users.
- XSS present — runs JS as your origin.
- Network attacker — only relevant without HTTPS / with mixed content.
- Malicious dependency / tag — code inside your build or page.
- Abusive logged-in user — hits your UI in unexpected ways (still validate server-side).
STRIDE-ish for FE
| Threat | Frontend angle |
|---|---|
| Spoofing | Open redirects, fake origin UX |
| Tampering | Unsigned client state trusted by server ❌ |
| Repudiation | Client logs only — server audit |
| Info disclosure | Tokens in storage, verbose errors |
| DoS | Less FE; watch unbounded client loops |
| Elevation | Hiding admin buttons ≠ authz |
Server enforces authz. Hiding a button is UX, not security.
Control map
XSS → safe sinks, sanitization, CSP, Trusted Types, HttpOnly cookies
CSRF → SameSite, CSRF tokens, no GET mutations
Clickjacking → frame-ancestors
Transport → HTTPS, no mixed content
Supply chain → lockfiles, SRI, minimize tags
Data → don’t put secrets in bundles
SPA-specific notes
- XSS is catastrophic with any client-readable token.
- CSRF matters for cookie sessions.
postMessageand iframes expand the boundary — model them explicitly.- Offline caches can retain sensitive HTML — be careful with SW caches.
Lightweight process
- Draw trust boundaries (browser, your API, third parties).
- List entry points (URL params, forms, messages, embeds).
- List sinks (DOM, navigation, storage).
- Assign controls + residual risk.
- Revisit when adding payments, UGC, or new third parties.
Interview out-loud
“I threat-model assets like sessions and privileged actions, then map XSS, CSRF, clickjacking, transport, and supply-chain to controls. UI hiding isn’t authz — the API enforces. SPAs make XSS especially expensive if tokens are JS-readable.”
Reviewer prompts
- What is the asset (session, PII, money movement)?
- What is the attacker capability (web, XSS, network, dependency)?
- Which control fails closed if misconfigured?
- Is the server still enforcing authz?
- Any new third party, iframe, or URL sink?
Residual risk note
Browser controls reduce likelihood and impact; they do not eliminate bugs. Prefer defense in depth: safe defaults in code, strict headers, and monitoring (CSP reports, auth anomaly alerts). When product pressure weakens a control, write down the accepted risk and a revisit date.
Related
Further depth
Teams often under-invest in this topic until an incident or CWV regression. Schedule a one-hour drill: reproduce the failure mode in DevTools, list the top three mitigations for your stack, and file tickets with owners. Revisit after the next major feature that touches networking, rendering, auth, or third parties — those are the moments regressions land. Keep primary documentation links in the runbook so on-call is not searching chat history at 2am.
Concrete artifacts to leave behind: a short architecture note, a CI assertion or header snapshot, and a dashboard panel (lab or field) that would have caught the last bug. Teaching the rest of the team the mental model matters as much as the one-line fix.
Further reading
Related guides
- CSRF Basics for SPAsCross-site request forgery against cookie sessions: SameSite, CSRF tokens, and SPA fetch patterns.
- Content Security Policy (CSP)Reduce XSS blast radius with CSP — script-src nonces/hashes, strict-dynamic, report-only rollout, and what CSP does not fix.
- JWT Storage PitfallsWhy localStorage JWTs are XSS bait, cookie alternatives, refresh patterns, and SPA session designs that age better.
- postMessage SecuritySecure window.postMessage: targetOrigin, event.origin checks, schema validation, and iframe bridges.
- Safe URL HandlingValidate href/src/navigation targets: block javascript: and data: traps, open redirects, and XSS via URLs.