Secure

Security Headers — The Protections You Get by Adding a Line

Security headers instruct the browser to enforce restrictions on your behalf: which sources may load scripts, whether the page can be framed, whether the connection may ever be plain HTTP, how much referrer information leaves. They are absent by default, and adding them is one of the highest-return-per-line changes available to a front-end developer.

When it helps

To find out where you stand, and to plan the order. The headers are not equally risky: frame options, content-type sniffing and referrer policy are almost always safe to add and take effect immediately. Content security policy is a different proposition — it is the most valuable of them and the one most likely to break your own site, because inline scripts and third-party widgets you forgot about will stop working the moment it is enforced.

Worth running automatically

Because these regress silently and specifically. A content security policy is tightly coupled to what the page loads, so adding an analytics tool or a chat widget can violate it — and the symptom is that feature not working, reported by whoever asked for it, days later, with no obvious connection to the policy. Checking the headers on a schedule catches the day one disappears; the more valuable version also watches for violations, which is how you learn a policy is blocking something you actually wanted.

What you get out of it

A clear picture of which browser-enforced protections you have and which are missing, with a sense of which ones are safe to add today and which need staging.

Also in Secure