Quick start#
This is the raw PHP path, the shortest one. Laravel and PSR-15 mount the same core as middleware; see the Next steps section at the bottom.
-
Add the package.
composer require waynestate/helmetExpected: Composer adds
waynestate/helmettocomposer.jsonand installs it with its dependencies. -
Boot it once, at the top of the front controller, before anything is echoed:
use function Waynestate\Helmet\helmet_boot; $helmet = helmet_boot([ 'preset' => 'citadel', ]);Expected:
helmet_boot()sends the headers, stripsX-Powered-By, and answers/upwith200 okbefore your code runs. It returns the nonce, the logger and the request ID. -
Ask the load balancer's question.
curl -sI http://localhost/upExpected:
200 ok, with the baseline headers on the response and noX-Powered-By. -
Put the nonce in your scripts.
$helmet['nonce']is the per-request CSP nonce: print the meta tag in<head>and put the nonce in your<script>tags.echo helmet_csp_nonce_meta($helmet['nonce']);Expected: inline scripts tagged with the nonce pass the CSP, because
script-srccarries the nonce plusstrict-dynamic.
What you built#
A raw PHP front controller where every response carries the baseline security headers, X-Powered-By is stripped,
/up answers the load balancer before your code runs, and inline scripts carry the per-request CSP nonce. One call,
and the floor is set.
Next steps#
- Go deeper by stack: Raw PHP, PSR-15 middleware, Laravel.
- What goes on the wire: The headers.
- Platform presets and proxies: Platform presets, HTTPS, and why the proxy list matters.
- Every knob: Environment variables.