Skip to content

Commit

Permalink
class files casesensitive
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Dec 22, 2018
1 parent 6c0da3d commit c1bd82c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions classes/SecurityHeaders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Bnomei;

class SecurityHeaders
{
private static function enabled()
{
return option('bnomei.securityheaders.enabled') && !static::isWebpack() && !static::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 $nonces = null;
public static function nonce($string, $value = null)
{
if (!static::$nonces) {
static::$nonces = [];
}
if ($value && is_string($value)) {
static::$nonces[$string] = $value;
}
return \Kirby\Toolkit\A::get(static::$nonces, $string);
}

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' ));
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-security-headers",
"type": "plugin",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"description": "Kirby 3 Plugin for easier Security Headers setup",
"authors": [
Expand Down

0 comments on commit c1bd82c

Please sign in to comment.