-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bruno Meilick <b@bnomei.com>
- Loading branch information
0 parents
commit f3f3597
Showing
8 changed files
with
1,012 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Bnomei; | ||
|
||
class SecurityHeaders | ||
{ | ||
private static function enabled() | ||
{ | ||
return option('bnomei.securityheaders.enabled') && !isWebpack() && !isLocalhost(); | ||
} | ||
|
||
public static function headers($headers) | ||
{ | ||
if (!static::enabled()) { | ||
return; | ||
} | ||
$options = option('bnomei.securityheaders.headers', []); | ||
$optionsKV = array_map(function ($k, $v) { | ||
return [ | ||
'name' => $k, | ||
'value' => $v, | ||
]; | ||
}, array_keys($options), $options); | ||
$headers = array_merge($headers, $optionsKV); | ||
|
||
foreach ($headers as $h) { | ||
header(sprintf('%s: %s', $h['name'], $h['value'])); | ||
} | ||
} | ||
|
||
private static function isWebpack() | ||
{ | ||
return !!( | ||
isset($_SERVER['HTTP_X_FORWARDED_FOR']) | ||
&& $_SERVER['HTTP_X_FORWARDED_FOR'] == 'webpack' | ||
); | ||
} | ||
|
||
private static function isLocalhost() | ||
{ | ||
return in_array($_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' )); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "bnomei/kirby3-security-headers", | ||
"type": "plugin", | ||
"version": "0.5.0", | ||
"license": "MIT", | ||
"description": "Kirby 3 Plugin for easier Security Headers setup", | ||
"autoload": { | ||
"files": [ | ||
"config.php" | ||
], | ||
"psr-4": { | ||
"Bnomei\\": "classes/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Bruno Meilick", | ||
"email": "b@bnomei.com" | ||
} | ||
], | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/k-next/kirby" | ||
} | ||
], | ||
"require": { | ||
"getkirby/cms": "3.0.*", | ||
"Martijnc/php-csp": "^1.0" | ||
}, | ||
"minimum-stability": "beta" | ||
} |
Oops, something went wrong.