Download the PHP package acolyte/laravel-security without Composer

On this page you can find all versions of the php package acolyte/laravel-security. 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

Laravel Security

Tests PHP Version Latest Version

Laravel Security is a configurable security-headers middleware package for Laravel applications.

It helps apply modern browser security controls including Content Security Policy, HSTS, Referrer-Policy, Permissions-Policy, MIME-sniffing protection, and frame restrictions. The package provides defense-in-depth and does not replace secure application design or infrastructure configuration.

Features

Requirements

Laravel PHP
12.x 8.2–8.5
13.x 8.3–8.5

Only combinations exercised by CI are claimed. See Laravel's support policy when choosing a framework version.

Installation

Laravel discovers LaravelSecurityServiceProvider automatically. Publish the documented configuration when you need to customize it:

Quick Start

Register the middleware globally in Laravel 12–13 in bootstrap/app.php:

Or attach SecurityHeaders::class to selected routes or route groups. Put it late enough in the middleware stack to inspect the completed response. If another middleware adds headers on its return path, middleware ordering determines which value wins.

Configuration

The published config/laravel-security.php contains comments for every option. Its defaults are equivalent to:

Set a supported simple policy to false to disable it. Set top-level enabled to false to leave responses unchanged.

Security Headers

HSTS

Strict-Transport-Security tells browsers to use HTTPS for future requests. The middleware emits it only when Laravel considers the request secure. When TLS terminates at a load balancer or reverse proxy, configure Laravel's trusted proxies correctly or HTTPS detection will be wrong.

This produces Strict-Transport-Security: max-age=31536000; includeSubDomains on HTTPS responses. Preload requires at least one year and include_subdomains; invalid combinations are rejected. Preloading is difficult to reverse and can make every subdomain unreachable if one lacks valid HTTPS. Submit a domain to browser preload lists only after a deliberate operational review.

Content Security Policy

CSP restricts where a browser may load and execute resources. It is disabled by default because a generic enforcing policy can break scripts, styles, images, third-party widgets, and development tooling. Build a policy for the actual application and deploy it in report-only mode first.

The builder preserves configured directive order, removes repeated values, supports valueless directives such as upgrade-insecure-requests, rejects malformed names and values, and replaces an existing CSP header rather than appending duplicates.

For inline scripts or styles that cannot be moved to external files, enable per-request nonces:

Use the generated value while rendering Blade:

The nonce is generated before the response renders and reused if the middleware runs more than once. Never cache nonce-bearing HTML independently of its CSP header, and never reuse a nonce across responses.

X-Content-Type-Options

The default X-Content-Type-Options: nosniff asks supporting browsers not to reinterpret script and stylesheet MIME types. Configure content_type_options as false to disable it; arbitrary values are rejected.

Referrer-Policy

The default is Referrer-Policy: strict-origin-when-cross-origin. Configure any standardized policy value supported by the package, such as no-referrer, or use false to disable it.

Permissions-Policy

An empty allowlist disables a browser feature. self, a valid URL, and the wildcard are supported:

This produces:

Browser support varies by directive; test the features your application relies on.

For a permanently enabled policy, the shorter form is also accepted: 'permissions_policy' => ['camera' => [], 'microphone' => []].

Frame Protection

CSP frame-ancestors is the modern control and should be your primary policy. X-Frame-Options remains enabled as a compatibility layer and accepts only DENY, SAMEORIGIN, or false. Keep CSP and X-Frame-Options semantically aligned.

X-Powered-By

When remove_x_powered_by is enabled, the middleware removes X-Powered-By from the outgoing Laravel response without touching unrelated headers. PHP, Nginx, Apache, a reverse proxy, CDN, or another upstream layer may inject the header after Laravel returns the response. Disable it at every responsible infrastructure layer; Laravel middleware cannot guarantee removal in every deployment.

Content Security Policy Examples

API application

An API that does not return browser-rendered HTML may not benefit from CSP. Leave it disabled while keeping the other default controls, or use a restrictive policy if API responses may be rendered:

CORS is intentionally not managed by this package. Use Laravel's native config/cors.php and choose origins, methods, headers, and credential behavior for the API's trust model.

Blade application

Start with the sources the application actually uses. Avoid adding 'unsafe-inline' simply to silence violations; prefer nonces or hashes where the application architecture supports them.

CSP report-only migration

Review reports, remove false positives, then switch report_only to false. A report endpoint receives attacker-controlled data and should be rate-limited, validated, size-limited, and monitored.

Per-environment behavior

Call env() only inside configuration files so Laravel configuration caching remains reliable:

Laravel Integration

The package is auto-discovered. For route-specific use:

Middleware can safely execute more than once: package-managed headers replace prior values instead of creating duplicate field lines. Server and proxy configuration still runs outside this middleware.

Custom Headers

Names and values must be strings; invalid field names and line breaks are rejected to prevent response-splitting mistakes. Custom headers replace an existing header of the same name. Prefer first-class options for policies the package understands because those options provide stronger validation.

Testing

Coverage requires PCOV or Xdebug. The suite uses PHPUnit and Orchestra Testbench.

Security Considerations

Security headers influence browser behavior. They do not prevent vulnerabilities in server-side code and do not replace authentication, authorization, input validation, context-aware output escaping, CSRF controls, dependency patching, safe file handling, TLS configuration, secret management, monitoring, or infrastructure security.

Upgrading

Version 2 is a major redesign. The nine legacy middleware entry points are replaced by SecurityHeaders; wildcard CORS and X-XSS-Protection are removed. See UPGRADE.md for mappings and a migration checklist.

Contributing

See CONTRIBUTING.md for the development workflow and expectations.

Security Policy

Please report suspected package vulnerabilities privately as described in SECURITY.md. Do not disclose an unpatched vulnerability in a public issue.

License

Laravel Security is open-source software licensed under the MIT License.


All versions of laravel-security with dependencies

PHP Build Version
Package Version
No informations.
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 acolyte/laravel-security contains the following files

Loading the files please wait ...