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 #12 [Security] XSS - SVG file upload vulnerability fixed (Rafikooo)
This PR was merged into the 1.9 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.9 <!-- see the comment below --> | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no <!-- don't forget to update the UPGRADE-*.md file --> | Related tickets | GHSA-4qrp-27r3-66fj | License | MIT There is a possibility to upload an SVG file containing XSS code in the admin panel. In order to perform an XSS attack, the file itself has to be open in a new card (or loaded outside of the IMG tag). The problem applies both to the files opened on the admin panel and shop pages. <!-- - 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 ------- 46ed54b [Security] XSS - SVG file upload vulnerability fixed
- Loading branch information
Showing
7 changed files
with
95 additions
and
5 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
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,59 @@ | ||
<?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\Functional; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use Sylius\Component\Core\Model\ProductImage; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\HttpFoundation\File\Exception\FileException; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\BrowserKit\Client; | ||
|
||
final class ImageUploaderTest extends WebTestCase | ||
{ | ||
/** @var Client */ | ||
private static $client; | ||
|
||
/** @test */ | ||
public function it_sanitizes_file_content_if_it_is_svg_mime_type(): void | ||
{ | ||
self::$client = static::createClient(); | ||
self::$container = self::$client->getContainer(); | ||
|
||
$imageUploader = self::$container->get('sylius.image_uploader'); | ||
$fileSystem = self::$container->get('gaufrette.sylius_image_filesystem'); | ||
|
||
$file = new UploadedFile(__DIR__ . '/../Resources/xss.svg', 'xss.svg'); | ||
Assert::assertStringContainsString('<script', $this->getContent($file)); | ||
|
||
$image = new ProductImage(); | ||
$image->setFile($file); | ||
|
||
$imageUploader->upload($image); | ||
|
||
$sanitizedFile = $fileSystem->get($image->getPath()); | ||
Assert::assertStringNotContainsString('<script', $sanitizedFile->getContent()); | ||
} | ||
|
||
private function getContent(UploadedFile $file): string | ||
{ | ||
$content = file_get_contents($file->getPathname()); | ||
|
||
if (false === $content) { | ||
throw new FileException(sprintf('Could not get the content of the file "%s".', $file->getPathname())); | ||
} | ||
|
||
return $content; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.