Skip to content

Commit

Permalink
inital commit (unstable)
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Jul 26, 2018
0 parents commit f3f3597
Show file tree
Hide file tree
Showing 8 changed files with 1,012 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
43 changes: 43 additions & 0 deletions classes/securityheaders.php
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' ));
}
}
32 changes: 32 additions & 0 deletions composer.json
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"
}
Loading

0 comments on commit f3f3597

Please sign in to comment.