Sikau

Security · Day 12 · about 45 min

Project: Security header audit

Check a response for missing security headers and unsafe cookies.

Cheap defences in the response

Many protections cost one line of server config. security headers tell the browser how to treat your page: only run our scripts, only use HTTPS, do not guess file types. A quick audit of a response's headers shows at a glance which doors were left open.

In this project you build the auditor itself: give it the headers of a response and it lists every problem, ready to paste into a ticket.

The headers that matter

Content-Security-Policy limits where scripts and other resources may load from, blunting XSS. Strict-Transport-Security (HSTS) tells the browser to use HTTPS only for this site for months, defeating downgrade attacks on cafe Wi-Fi. X-Content-Type-Options: nosniff stops the browser from guessing a file's type, so an uploaded image can't be run as a script.

Cookies carry their own flags: HttpOnly, Secure and SameSite. Header names are case-insensitive, so Content-Security-Policy and content-security-policy mean the same thing, and a response can set several cookies at once.

Content-Security-Policy: default-src 'self'
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Set-Cookie: sid=abc; HttpOnly; Secure; SameSite=Lax

The rest of this lesson

  • Audits find, people fixexplain
  • Which header stops it?match
  • Running an auditorder
  • A safe responsefill
  • auditHeaderschallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browserright here

Continue with Google

See all 12 lessons of Security