Web SecurityWeb Security · Lesson 09

Security Headers, TLS & Cookies

Hardening the transport and browser layer.

Video tutorialTrack course · freeCodeCamp
Speed
Next lesson
Watch 00:00 · 2 checkpoints Watch on YouTube More on this topic
Transcript & captions
7/7
HeaderPurpose
Content-Security-PolicyRestricts script/style/frame sources - kills most XSS
Strict-Transport-SecurityForces HTTPS for future visits
X-Content-Type-Options: nosniffStops MIME sniffing
Referrer-PolicyPrevents URL leakage to third parties
Permissions-PolicyDisables camera, mic, geolocation by default
frame-ancestorsBlocks clickjacking via framing
A reasonable starting CSPjs
Content-Security-Policy: default-src 'self';
  script-src 'self';
  style-src 'self' 'unsafe-inline';
  img-src 'self' data: https:;
  frame-ancestors 'none';
  base-uri 'self';
  • Serve everything over TLS 1.2+ and redirect HTTP to HTTPS.
  • Cookies: Secure, HttpOnly, SameSite, minimal scope and lifetime.
  • Disable weak ciphers and keep certificates renewed automatically.
  • Do not leak server versions in headers or error pages.

Knowledge check

0/2 answered

Which header most directly reduces XSS impact?

HSTS does what?