FSD Frontend System Design

Part II β€” The Shield Β· Lesson 3.1

Security Overview

In one lineEverything the browser receives is attacker-reachable β€” your job is to shrink what a breach can reach.

Where you've seen itAny page with an analytics tag. That third-party script runs with exactly the same powers as your own application code.

  • Time12 min
  • DiagramAttack surface map of a browser app
  • Chapter3 Β· Security

Diagram

diagram
ATTACK SURFACE OF A BROWSER APP

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ The browser tab ─────────────────────────┐
  β”‚                                                                  β”‚
  β”‚  Your JS ── same origin ──► cookies, localStorage, DOM, fetch    β”‚
  β”‚     β–²                                                            β”‚
  β”‚     β”‚ XSS (3.2)        injected script gets ALL of the above     β”‚
  β”‚     β”‚ 3rd-party (3.7)  npm packages + CDN tags, same powers      β”‚
  β”‚     β”‚ iframe (3.3)     you embedded, or you got embedded         β”‚
  β”‚                                                                  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚ every request carries cookies automatically
                  β–Ό                    ← CSRF (3.15) rides this
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Your server   ── SSRF (3.10) ──► internal network                β”‚
  β”‚               ── SSJI (3.11) ──► code execution                  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
diagram
THE DEFENCE LAYERS β€” each one assumes the one above failed

  1. Don't trust input      validate + sanitize        (3.9)
  2. Don't trust output     escape by context          (3.2)
  3. Don't trust scripts    CSP + SRI                  (3.4, 3.13)
  4. Don't trust embeds     frame-ancestors, sandbox   (3.3, 3.12)
  5. Don't trust the wire   HTTPS + HSTS               (3.6)
  6. Don't trust yourself   no secrets in the bundle   (3.5)

How it works

  1. Enumerate what the attacker wants: session cookies, personal data, the ability to act as the user.
  2. Enumerate the ways in: your input fields, your URLs, your dependencies, your embeds, your API.
  3. Assume one layer fails and ask what the blast radius is. That question is the whole discipline.
  4. Prefer configuration over code β€” a header applies to every route; a code fix applies to one.

Trade-offs

PrincipleIn practice
Defence in depthEscape output and ship a CSP
Least privilegeHttpOnly cookies, scoped tokens, Permissions-Policy
Fail closedUnknown input rejected, not "cleaned up"
Never trust the clientEvery check re-run on the server

Interview angle

"How do you think about security on the frontend?"

  • Name the surfaces β€” injection, third-party code, embedding, transport, and the client's inability to keep secrets.
  • Say the frontend can only reduce risk; authorisation is always re-checked server-side.
  • Lead with the two highest-leverage moves: contextual output escaping and a strict CSP.

Recap

  • Injected code inherits every power your own code has.
  • Layer defences so a single failure isn't a breach.
  • Headers scale better than fixes, because they cover routes you forgot.