-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic security headers * Remove XSS Header (not relevent) * Fix config name * Use Arr::get() * Add tests * Re-fix the StoreConfig step for fresh installs Co-authored-by: luceos <luceos@users.noreply.github.com> Co-authored-by: Alexander Skvortsov <askvortsov1@users.noreply.github.com>
- Loading branch information
1 parent
9711af4
commit 7eea247
Showing
7 changed files
with
135 additions
and
2 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
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
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,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Http\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface as Middleware; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class ContentTypeOptionsHeader implements Middleware | ||
{ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$response = $handler->handle($request); | ||
|
||
return $response->withAddedHeader('X-Content-Type-Options', 'nosniff'); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Http\Middleware; | ||
|
||
use Flarum\Foundation\Config; | ||
use Illuminate\Support\Arr; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface as Middleware; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class ReferrerPolicyHeader implements Middleware | ||
{ | ||
protected $policy = ''; | ||
|
||
public function __construct(Config $config) | ||
{ | ||
$this->policy = Arr::get($config, 'headers.referrerPolicy') ?? 'same-origin'; | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$response = $handler->handle($request); | ||
|
||
return $response->withAddedHeader('Referrer-Policy', $this->policy); | ||
} | ||
} |
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
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,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tests\integration\middleware; | ||
|
||
use Flarum\Testing\integration\TestCase; | ||
|
||
class ContentTypeOptionsTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function has_content_type_options_header() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
$this->assertArrayHasKey('X-Content-Type-Options', $response->getHeaders()); | ||
$this->assertEquals('nosniff', $response->getHeader('X-Content-Type-Options')[0]); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tests\integration\middleware; | ||
|
||
use Flarum\Testing\integration\TestCase; | ||
|
||
class ReferrerPolicyTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function has_referer_header() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
$this->assertArrayHasKey('Referrer-Policy', $response->getHeaders()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function has_default_referer_policy() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
$this->assertEquals('same-origin', $response->getHeader('Referrer-Policy')[0]); | ||
} | ||
} |