Download the PHP package jeffersongoncalves/laravel-security-headers without Composer

On this page you can find all versions of the php package jeffersongoncalves/laravel-security-headers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-security-headers

![Laravel Security Headers](https://raw.githubusercontent.com/jeffersongoncalves/laravel-security-headers/master/art/jeffersongoncalves-laravel-security-headers.png)

Laravel Security Headers

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This Laravel package stamps a configurable set of baseline security headers onto your HTTP responses via a single middleware. Every header value and the full Content-Security-Policy directive map are driven by config/security-headers.php, so you can tune or disable each one without touching code.

The headers it manages:

Installation

You can install the package via composer:

You can publish the config file with:

Usage

The package ships a single middleware: JeffersonGoncalves\SecurityHeaders\Middleware\SecurityHeaders. The service provider auto-registers a security-headers route-middleware alias for you, but it does not apply the middleware globally — you must still attach it to a route or group. Place it as the outermost middleware of the group you want protected so it also stamps cached (HIT) responses produced further down the stack.

Attach it via the registered alias

The alias security-headers is wired up automatically, so you can use it directly on a route or group:

Or apply it to the whole web group (Laravel 11+)

In bootstrap/app.php:

Legacy kernel (Laravel 10 style)

Add the middleware to a group in app/Http/Kernel.php:

Configuration

After publishing, config/security-headers.php exposes three blocks.

Static headers

Each entry is stamped onto every response. Set any value to null to skip that header:

Customizing the Content-Security-Policy

The CSP header is assembled from the associative directives map, preserving order. A value may be a string or an array of source expressions. A directive whose value is null (or an empty string) is emitted as a valueless directive (e.g. upgrade-insecure-requests). Set csp.enabled to false to drop the header entirely.

The shipped default is a strict, first-party-only policy — no 'unsafe-*', no third-party origins — so it is a genuine XSS backstop:

Nonces for inline scripts

Rather than reaching for 'unsafe-inline', allow specific inline scripts with a per-request nonce. Put the {nonce} placeholder in a directive — the middleware substitutes it with a fresh, random per-request value:

Then emit the matching nonce in your Blade markup with the @cspNonce directive (or the csp_nonce() helper):

Both the header and the view receive the same value for that request, so the script validates while injected markup (which cannot guess the nonce) is blocked.

Report-only mode and violation reporting

Set report-only to emit Content-Security-Policy-Report-Only instead of the enforcing header (useful for rolling out a policy without breaking pages). report-uri / report-to are appended as CSP directives when non-null:

Opt-in: GTM / gtag / Alpine.js (permissive)

If you rely on inline Google Tag Manager / gtag and Alpine.js (which evaluates expressions via new Function, requiring 'unsafe-eval') and cannot adopt nonces, you can loosen the policy. This removes the CSP's XSS protection — pair it with output sanitization (e.g. symfony/html-sanitizer) for any untrusted markup you render:

HSTS

Strict-Transport-Security is only stamped over real HTTPS and never while the app is in an excluded environment (['local'] by default — a cached max-age on a *.test domain is a pain to undo):

preload is a near-irreversible commitment. Enabling it and submitting your domain to hstspreload.org hard-codes HTTPS-only for the apex domain and every subdomain into browsers shipped worldwide. Removal is slow (months) and painful. Leave it false unless you are certain every current and future subdomain serves valid TLS. It defaults to false.

HSTS depends on a correct $request->secure()

HSTS is only emitted when Laravel considers the request secure ($request->secure()). Behind a TLS-terminating proxy or load balancer (the app receives plain HTTP on the back end), secure() returns false and HSTS will be silently skipped unless you configure trusted proxies. Make sure your TrustProxies middleware / bootstrap/app.php trustProxies(...) config is set so the X-Forwarded-Proto header is honoured — otherwise the proxy must add HSTS itself.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-security-headers with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0|^12.0|^13.0
spatie/laravel-package-tools Version ^1.14.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jeffersongoncalves/laravel-security-headers contains the following files

Loading the files please wait ...