Skip to content

Commit

Permalink
fix x-powered-by header key, closes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
bepsvpt committed Jul 27, 2020
1 parent e6ebe12 commit b405451
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/secure-headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
'x-permitted-cross-domain-policies' => 'none',

/*
* X-Power-By
* X-Powered-By
*
* Note: it will not add to response header if the value is empty string.
*/

'x-power-by' => '',
'x-powered-by' => '',

/*
* X-XSS-Protection
Expand Down
2 changes: 1 addition & 1 deletion src/SecureHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected function miscellaneous(): array
'X-Download-Options' => $this->config['x-download-options'],
'X-Frame-Options' => $this->config['x-frame-options'],
'X-Permitted-Cross-Domain-Policies' => $this->config['x-permitted-cross-domain-policies'],
'X-Power-By' => $this->config['x-power-by'],
'X-Powered-By' => $this->config['x-powered-by'] ?? ($this->config['x-power-by'] ?? ''),
'X-XSS-Protection' => $this->config['x-xss-protection'],
'Referrer-Policy' => $this->config['referrer-policy'],
'Server' => $this->config['server'],
Expand Down
25 changes: 20 additions & 5 deletions tests/SecureHeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,37 @@ public function testServerHeader()
$this->assertSame('Example', $headers['Server']);
}

public function testXPowerByHeader()
public function testXPoweredByHeader()
{
$config = $this->config();

$this->assertArrayNotHasKey(
'X-Power-By',
'X-Powered-By',
(new SecureHeaders($config))->headers()
);

$config['x-power-by'] = 'Example';
$config['x-powered-by'] = 'Example';

$headers = (new SecureHeaders($config))->headers();

$this->assertArrayHasKey('X-Power-By', $headers);
$this->assertArrayHasKey('X-Powered-By', $headers);

$this->assertSame('Example', $headers['X-Powered-By']);

// ensure backward compatibility

unset($config['x-powered-by']);

$this->assertArrayNotHasKey(
'X-Powered-By',
(new SecureHeaders($config))->headers()
);

$config['x-power-by'] = 'Example';

$this->assertArrayHasKey('X-Powered-By', $headers);

$this->assertSame('Example', $headers['X-Power-By']);
$this->assertSame('Example', $headers['X-Powered-By']);
}

public function testContentSecurityPolicy()
Expand Down

0 comments on commit b405451

Please sign in to comment.