forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #14 [Security] Clickjacking vulnerability fixed (ernestWarwas)
This PR was merged into the 1.9 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.9 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | License | MIT There was a possibility to load a page within an iframe which is enabling to the possibility to perform a clickjacking attack. <!-- - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- 0886078 listener added to finish response with X-Frame-Options sameorigin header c236431 suggested review changes
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/Sylius/Bundle/CoreBundle/EventListener/XFrameOptionsSubscriber.php
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,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
final class XFrameOptionsSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
KernelEvents::RESPONSE => 'onKernelResponse', | ||
]; | ||
} | ||
|
||
public function onKernelResponse(ResponseEvent $event): void | ||
{ | ||
if (!$this->isMainRequest($event)) { | ||
return; | ||
} | ||
|
||
$response = $event->getResponse(); | ||
|
||
$response->headers->set('X-Frame-Options', 'sameorigin'); | ||
} | ||
|
||
private function isMainRequest(ResponseEvent $event): bool | ||
{ | ||
if (\method_exists($event, 'isMainRequest')) { | ||
return $event->isMainRequest(); | ||
} | ||
|
||
return $event->isMasterRequest(); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Tests\Controller; | ||
|
||
use ApiTestCase\JsonApiTestCase; | ||
|
||
final class XFrameOptionsTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
public function it_sets_frame_options_header(): void | ||
{ | ||
$this->client->request('GET', '/'); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$this->assertSame('sameorigin', $response->headers->get('X-Frame-Options')); | ||
} | ||
} |