PHPackages                             zae/strict-transport-security - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. zae/strict-transport-security

ActiveLibrary[HTTP &amp; Networking](/categories/http)

zae/strict-transport-security
=============================

Set the HSTS header to enable HTTP Strict Transport Security

0.0.3(10y ago)7123.5k↓34.2%1MITPHP

Since Jun 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Zae/strict-transport-security)[ Packagist](https://packagist.org/packages/zae/strict-transport-security)[ RSS](/packages/zae-strict-transport-security/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

strict-transport-security
=========================

[](#strict-transport-security)

[![Latest Version](https://camo.githubusercontent.com/1d3679315377935455ff0564ff66fb7fc5a9e67b3b9829f001221ce2aec6406c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f5a61652f7374726963742d7472616e73706f72742d73656375726974792e7376673f7374796c653d666c61742d737175617265)](https://github.com/Zae/strict-transport-security/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/33815d2fdb0f3ee4d8d602e82d50fefd6ce91ee2db08aeef6fc7f4cebc831614/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5a61652f7374726963742d7472616e73706f72742d73656375726974792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Zae/strict-transport-security)[![Total Downloads](https://camo.githubusercontent.com/1027c68776b3f289ff8b77d8c0f685db229e81467b99d7e5a17e669b0c1a5ce8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f5a61652f7374726963742d7472616e73706f72742d73656375726974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Zae/strict-transport-security)

Enable HTTP Strict Transport Security using HTTP Middleware

L4 / L5
-------

[](#l4--l5)

Middleware is available for both Laravel 4 and 5.

Install
-------

[](#install)

Via Composer

```
$ composer require zae/strict-transport-security
```

Usage
-----

[](#usage)

### Laravel 5

[](#laravel-5)

Add the class `Zae\StrictTransportSecurity\Middleware\L5\StrictTransportSecurity` to the `$middlewares` array.

```
#app/Http/Kernel.php

protected $middleware = [
	'Illuminate\View\Middleware\ShareErrorsFromSession',
	'Zae\StrictTransportSecurity\Middleware\L5\StrictTransportSecurity',
];
```

It's not strictly required to use the middleware but if you want to use the `vendor:publish` command add the service provider `Zae\StrictTransportSecurity\ServiceProvider\L5HTSTServiceProvider` to the `providers` array in the app config.

```
#config/app.php

return [
	'providers' => [
		Illuminate\View\ViewServiceProvider::class,

		Zae\StrictTransportSecurity\ServiceProvider\L5HTSTServiceProvider::class,
	],
];
```

Publish the config with `php artisan vendor:publish`. This file will be created at `config/hsts.php`.

### Laravel 4

[](#laravel-4)

Add the serviceprovider to the list of service providers: `Zae\StrictTransportSecurity\ServiceProvider\L4HTSTServiceProvider`

```
#app/config.php

'providers' => array(
	'Illuminate\Foundation\Providers\ArtisanServiceProvider',
	'Illuminate\Auth\AuthServiceProvider',

	'Zae\StrictTransportSecurity\ServiceProvider\L4HTSTServiceProvider',
),
```

### Silex Example

[](#silex-example)

```
require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app = new Silex\Application();

$app->get('/', function(Request $request) {
return new Response('Hello world!', 200);
});

$app = (new Stack\Builder())
->push('Zae\StrictTransportSecurity\Middleware\L4\StrictTransportSecurity', [new \Zae\StrictTransportSecurity\HSTS(new Illuminate\Config\Repository())])
->resolve($app)
;

$request = Request::createFromGlobals();
$response = $app->handle($request)->send();

$app->terminate($request, $response);
```

### Symfony Example

[](#symfony-example)

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();

$app = (new Stack\Builder())
	->push('Zae\StrictTransportSecurity\Middleware\L4\StrictTransportSecurity', [new \Zae\StrictTransportSecurity\HSTS(new Illuminate\Config\Repository())])
	->resolve($app)
;

$kernel = $stack->resolve($kernel);

Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
```

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Contributions are welcome via pull requests on github.

Credits
-------

[](#credits)

- [Ezra Pool](https://github.com/Zae)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Total

3

Last Release

3737d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7195cfa9749ba405e65f0ff1ef74293f2d518bea06b2588d04179baad63b3e8c?d=identicon)[Zae](/maintainers/Zae)

---

Top Contributors

[![Zae](https://avatars.githubusercontent.com/u/96126?v=4)](https://github.com/Zae "Zae (8 commits)")[![RobertBoes](https://avatars.githubusercontent.com/u/2871897?v=4)](https://github.com/RobertBoes "RobertBoes (2 commits)")

---

Tags

httpmiddlewarelaravelssllaravel 5Laravel 4hstsStackPHPtslstrict transport security

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zae-strict-transport-security/health.svg)

```
[![Health](https://phpackages.com/badges/zae-strict-transport-security/health.svg)](https://phpackages.com/packages/zae-strict-transport-security)
```

###  Alternatives

[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[matthewbdaly/laravel-etag-middleware

A Laravel middleware for adding ETags to HTTP requests to improve response times

64326.0k2](/packages/matthewbdaly-laravel-etag-middleware)[tomschlick/request-migrations

HTTP Request Migrations

1844.5k](/packages/tomschlick-request-migrations)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[laravel-shift/curl-converter

A command line tool to convert curl requests to Laravel HTTP requests.

935.3k](/packages/laravel-shift-curl-converter)[middlewares/https

Middleware to redirect to https and adds the Strict-Transport-Security header

1389.1k3](/packages/middlewares-https)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
