Part II β The Shield
3 Security
GoalKnow the top frontend attack surfaces and the header, config, or code change that closes each one.
- 3.1 Security Overview Everything the browser receives is attacker-reachable β your job is to shrink what a breach can reach.
- 3.2 Cross-site Scripting (XSS) Untrusted text becomes executable code, and that code owns the user's session.
- 3.3 iFrame Protection Two problems: who may frame you, and what the frames you embed are allowed to do.
- 3.4 Security Headers Six response headers that close whole attack classes without touching application code.
- 3.5 Client-side Security The client is fully controlled by the user β it can enforce nothing and keep no secret.
- 3.6 Secure Communication (HTTPS) TLS gives you three things at once: encryption, integrity, and proof of who you're talking to.
- 3.7 Dependency Security You wrote 5% of the code you ship β the other 95% is your attack surface too.
- 3.8 Compliance & Regulation Consent gates data collection, and the frontend is where that gate is actually built.
- 3.9 Input Validation and Sanitization Validate shape on the way in, escape by context on the way out β they are different jobs.
- 3.1 Server-Side Request Forgery (SSRF) Your server fetches a URL the attacker chose, from inside your trusted network.
- 3.11 Server-side JavaScript Injection (SSJI) User input reaches an evaluator on your Node server, and now they own the process.
- 3.12 Feature Policy | Permissions-Policy Switch off browser capabilities your app never uses β for your code and every frame you embed.
- 3.13 Subresource Integrity (SRI) Pin a cryptographic hash to every CDN script, so altered code simply refuses to run.
- 3.14 Cross-Origin Resource Sharing (CORS) The browser blocks cross-origin reads by default; CORS is the server's way of granting an exception.
- 3.15 Cross-Site Request Forgery (CSRF) Another site makes the user's browser send an authenticated request β cookies attach automatically.
Capstone
Write a Content-Security-Policy for a React app that loads Google Fonts, Stripe Checkout, and Sentry β then explain every directive.