Skip to content

Commit 58152e6

Browse files
committed
Attach Security Headers to Laravel Application
1 parent 73f9700 commit 58152e6

File tree

70 files changed

+1746
-5379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1746
-5379
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

INSTALLATION.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
## [Blog Application Installation Guide](https://packagist.org/packages/monish-khatri/blog-application)
1+
## [Laravel Security Headers Installation Guide](https://packagist.org/packages/monish-khatri/security-headers)
22
<p>
3-
<a href="https://packagist.org/packages/lmonish-khatri/blog-application">
4-
<img src="https://img.shields.io/packagist/dt/monish-khatri/blog-application" alt="Total Downloads">
3+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
4+
<img src="https://img.shields.io/packagist/dt/monish-khatri/security-headers" alt="Total Downloads">
55
</a>
6-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
7-
<img src="https://img.shields.io/packagist/v/monish-khatri/blog-application" alt="Latest Stable Version">
6+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
7+
<img src="https://img.shields.io/packagist/v/monish-khatri/security-headers" alt="Latest Stable Version">
88
</a>
9-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
10-
<img src="https://img.shields.io/packagist/l/monish-khatri/blog-application" alt="License">
9+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
10+
<img src="https://img.shields.io/packagist/l/monish-khatri/security-headers" alt="License">
1111
</a>
12-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
13-
<img src="https://img.shields.io/packagist/stars/monish-khatri/blog-application" alt="License">
12+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
13+
<img src="https://img.shields.io/packagist/stars/monish-khatri/security-headers" alt="License">
1414
</a>
1515
</p>
1616

17-
### Follow the below steps to install blog application
17+
### Follow the below steps to install security header package
1818
- Install the package using
19-
- `composer require monish-khatri/blog-application`
19+
- `composer require monish-khatri/security-headers`
2020
- Run below command to publish package classes
21-
- `php artisan blog:install`
22-
- Finally, Run the migrations to create package tables
23-
- `php artisan migrate`
21+
- `php artisan security-headers:install`
2422
- You can publish the package config file & change site logo and favicon with email preference
25-
- `php artisan vendor:publish --provider="MonishKhatri\Blog\BlogServiceProvider" --tag="config"`
23+
- `php artisan vendor:publish --provider="MonishKhatri\SecurityHeaders\SecurityHeadersServiceProvider" --tag="config"`

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<p align="center"><img alt="Laravel 9" border="0" data-original-height="420" data-original-width="1000" height="269" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiKIANl_S4hKyyLC6IH5Y6979pHHGpeqZxv-2aEb-XvKzBXfB6PeljGbf1W8PAEWBguIVxy6VsBs0pwuw-9b3emV_hI3QzNbcm2J9HNnye7eHoDaCQxMzY0moh0yaHqu3kpDHxjL_aKrB-oN7bTyBYmoLZgdkmibuxNLDuK_YDDG7_qnE0Og4Xp_Viwg/w643-h269/l9.png" width="643"></p>
22

33
<p align="center">
4-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
5-
<img src="https://img.shields.io/packagist/dt/monish-khatri/blog-application" alt="Total Downloads">
4+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
5+
<img src="https://img.shields.io/packagist/dt/monish-khatri/security-headers" alt="Total Downloads">
66
</a>
7-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
8-
<img src="https://img.shields.io/packagist/v/monish-khatri/blog-application" alt="Latest Stable Version">
7+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
8+
<img src="https://img.shields.io/packagist/v/monish-khatri/security-headers" alt="Latest Stable Version">
99
</a>
10-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
11-
<img src="https://img.shields.io/packagist/l/monish-khatri/blog-application" alt="License">
10+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
11+
<img src="https://img.shields.io/packagist/l/monish-khatri/security-headers" alt="License">
1212
</a>
13-
<a href="https://packagist.org/packages/monish-khatri/blog-application">
14-
<img src="https://img.shields.io/packagist/stars/monish-khatri/blog-application" alt="License">
13+
<a href="https://packagist.org/packages/monish-khatri/security-headers">
14+
<img src="https://img.shields.io/packagist/stars/monish-khatri/security-headers" alt="License">
1515
</a>
1616
</p>
1717

1818
## Introduction
1919

20-
Blog Application provides a minimal and simple starting point for building a Laravel application . Styled with Tailwind, Blog Application publishes Blog,Comment,Tag controllers,views,requests & many more things to your application that can be easily customized based on your own application's needs.
20+
Package provides a minimal and simple integration to attach security headers for building a secure Laravel application.
21+
This package publishes config file to your application that can be easily customized based on your own application's needs.
2122

2223
## Code of Conduct
2324

@@ -26,12 +27,12 @@ In order to ensure that the Laravel community is welcoming to all, please review
2627

2728
## Installation guide
2829

29-
You can setup the Blog Application by following given steps in [Installation guide](INSTALLATION.md).
30+
You can setup the Security Headers by following given steps in [Installation guide](INSTALLATION.md).
3031

3132
## Contributing
3233
Pull requests and feedback are very welcome :)
33-
on GitHub at https://github.com/monish-khatri/laravel-blog-application
34+
on GitHub at https://github.com/monish-khatri/security-headers
3435

3536
## License
3637

37-
Laravel Blog Application is open-sourced software licensed under the [MIT license](LICENSE.md).
38+
Laravel Security Headers is open-sourced software licensed under the [MIT license](LICENSE.md).

composer.json

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
{
2-
"name": "monish-khatri/blog-application",
3-
"description": "Blog Application using Laravel 9",
2+
"name": "monish-khatri/security-headers",
3+
"description": "Attach OWASP security related headers to HTTP response.",
44
"type": "library",
55
"license": "MIT",
6+
"keywords": [
7+
"laravel",
8+
"header",
9+
"https",
10+
"hsts",
11+
"csp",
12+
"except-ct",
13+
"feature-policy",
14+
"clear-site-data",
15+
"referrer-policy",
16+
"content-security-policy"
17+
],
618
"autoload": {
719
"psr-4": {
8-
"MonishKhatri\\Blog\\": "src/"
20+
"MonishKhatri\\SecurityHeaders\\": "src/"
921
}
1022
},
1123
"authors": [
@@ -16,19 +28,13 @@
1628
],
1729
"minimum-stability": "dev",
1830
"require": {
19-
"php": "^8.0.2",
20-
"kyslik/column-sortable": "^6.4",
21-
"laravel/breeze": "^1.13",
22-
"laravel/ui": "^4.1"
31+
"php": "^8.0.2"
2332
},
2433
"extra": {
2534
"laravel": {
2635
"providers": [
27-
"MonishKhatri\\Blog\\BlogServiceProvider"
28-
],
29-
"aliases": {
30-
"Blog": "App\\Models\\Blog"
31-
}
36+
"MonishKhatri\\SecurityHeaders\\SecurityHeadersServiceProvider"
37+
]
3238
}
3339
}
3440
}

composer.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BlogServiceProvider.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/Builders/Builder.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace MonishKhatri\SecurityHeaders\Builders;
4+
5+
abstract class Builder
6+
{
7+
/**
8+
* Builder config.
9+
*
10+
* @var array<mixed>
11+
*/
12+
protected $config = [];
13+
14+
/**
15+
* Builder constructor.
16+
*
17+
* @param array<mixed> $config
18+
*/
19+
public function __construct(array $config = [])
20+
{
21+
$this->config = $config;
22+
}
23+
24+
/**
25+
* Get result.
26+
*
27+
* @return string
28+
*/
29+
abstract public function get(): string;
30+
}

src/Builders/ClearSiteDataBuilder.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace MonishKhatri\SecurityHeaders\Builders;
4+
5+
final class ClearSiteDataBuilder extends Builder
6+
{
7+
/**
8+
* Clear Site Data whitelist directives.
9+
*
10+
* @var array<string, bool>
11+
*/
12+
protected $whitelist = [
13+
'cache' => true,
14+
'cookies' => true,
15+
'storage' => true,
16+
'executionContexts' => true,
17+
];
18+
19+
/**
20+
* {@inheritDoc}
21+
*/
22+
public function get(): string
23+
{
24+
if ($this->config['all'] ?? false) {
25+
return '"*"';
26+
}
27+
28+
$targets = array_intersect_key($this->config, $this->whitelist);
29+
30+
$needs = array_filter($targets);
31+
32+
$directives = array_map(function (string $directive) {
33+
return sprintf('"%s"', $directive);
34+
}, array_keys($needs));
35+
36+
return implode(', ', $directives);
37+
}
38+
}

0 commit comments

Comments
 (0)