Secure Headers for PHP

1 Jan, 2017
Recently I’ve been working on a drop in class to manage certain “Secure Headers” in PHP.
By “Secure Headers”, I’m of course talking about those mentioned in the OWASP Secure Headers Project.
The project, SecureHeaders is available on GitHub.
If you’re familiar with PHP, you’ll know that adding a header is actually quite easy. For example, HSTS can be configured in a single line as follows:
header(‘Strict-Transport-Security: max-age=31536000; includeSubDomains; preload’);
In-fact, you could configure any one of these headers in exactly the same way. So why use a 2.3k line PHP class instead of a one liner fix for each header?
I started the project as a small class to use for myself to manage CSP policies.
At the time of writing, this is my CSP string:
default-src ‘none’; script-src ‘self’ ‘nonce-noWJFLxtYDQCaRhA3wzbpnnj0ayxstr6mVat+VcB’ ‘strict-dynamic’; style-src ‘self’ ‘nonce-AzuI9nGHk86GV7NJ5LNZdsKE7mJeUlDPggnW1/R8’; img-src ‘self’ data:; font-src ‘self’; base-uri ‘self’; connect-src ‘self’; frame-ancestors ‘none’; object-src ‘none’; block-all-mixed-content; upgrade-insecure-requests; report-uri; child-src; frame-src; form-action;
Obviously, this is not a format that lends itself nicely to debugging and maintaining. While some URIs might be obvious as to their purpose upon reading, things like, for example,

Original URL:

Original article

Comments are closed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: