Every response this site sends carries a few extra headers that tell the browser what to refuse. The usual advice treats them as one job: turn them all on. We split them into three layers instead, because getting one wrong costs almost nothing, getting another wrong locks readers out, and getting the third wrong breaks the site. And one of them, once sent, cannot be taken back from the server at all.
The headers that stay on
Two headers are always on. The first tells the browser to take the declared content type at face value: a file served as plain text must not be re-interpreted and run as a script. The second says other sites may not embed these pages in a frame, so a page cannot be silently wrapped inside a stranger's page and clicked through.
These two are cheap to get wrong. If either one broke something, the breakage would show up at once, in plain sight, and the next deploy would fix it. A header whose mistake is visible and reversible belongs on from the start.
Turning a security filter off
The third header in that always-on layer looks like a mistake: it switches the browser's old cross-site scripting filter off. The value is zero, on purpose.
Modern browsers removed that filter years ago, so the header does nothing for them. In the older browsers that still honor it, the filter's habit of selectively rewriting page content had known flaws, and those flaws could themselves be turned into a way to inject content. Leaving it on would mean trusting a broken filter to do a job it no longer does well.
So the filter stays off, and the real defence against injected scripts is supposed to come from somewhere else — the layer that is still empty.
One day, on purpose
The next header tells the browser to reach this site only over an encrypted connection, never plain HTTP. It is live, but its timer is one day.
The reason is where the instruction lives. It is stored in the visitor's browser, not on the server. The server cannot retract it. The only way to cancel it is for the site itself to send a new instruction saying zero days — and that only works while the site is up and reachable.
If the certificate lapses, or the site goes dark, the browser keeps enforcing the old instruction and refuses the connection, with no way for the reader to click through. The only way out is waiting for the timer to run out. A one-day timer caps that worst case at one day. It stays short until encrypted access has proven stable for a while; only then does it get longer.
The layer left empty
The strongest layer is the one not sent at all. A content security policy is a whitelist: only resources from approved sources may load, so even a script that gets injected into a page is refused. It is the last line of defence against injected scripts, and it is also the layer most likely to break a working site.
The front end here is full of inline scripts and styles, and a whitelist that forbids them would break pages that work today. So the policy stays off, and the plan for turning it on is written down in steps: first send it in report-only mode, with an address to collect the violation reports; watch those reports for one to two weeks; only then switch it to enforced.
A policy that breaks the product on day one does not protect anyone. It teaches everyone to switch it off and leave it off. An empty layer, with a date for filling it, is the honest version.
Sort by how you undo it
The question that produced this split was what happens if this one is wrong, and how do I undo it.
If a mistake is cheap and visible, turn the header on. If a mistake locks readers out, start with the shortest timer that still does the job. If a mistake breaks the product, watch first and enforce later. Three layers, because the cost of being wrong comes in three sizes.
About the author
- Writing about ebook technology.
Comments
Join the discussionNo comments yet. Be the first to comment.