Skip to content

Commit

Permalink
fix: security advisory GHSA-92rv-4j2h-8mjj
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpozzi committed Sep 6, 2023
1 parent 409ec35 commit 8d893a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,11 @@ protected function executeCommand($command)
*/
protected function prepareOutput($filename, $overwrite)
{
if (\strpos($filename, 'phar://') === 0) {
throw new InvalidArgumentException('The output file cannot be a phar archive.');
$parsedFilename = parse_url($filename);
$scheme = isset($parsedFilename['scheme']) ? mb_strtolower($parsedFilename['scheme']) : '';

Check failure on line 629 in src/Knp/Snappy/AbstractGenerator.php

View workflow job for this annotation

GitHub Actions / PHP 7.1 tests (Symfony 4.4)

Cannot access offset 'scheme' on array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false.

if ($scheme !== '' && $scheme !== 'file') {
throw new InvalidArgumentException(sprintf('The output file scheme is not supported. Expected \'\' or \'file\' but got \'%s\'.', $scheme));
}

$directory = \dirname($filename);
Expand Down
24 changes: 24 additions & 0 deletions tests/Knp/Snappy/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,30 @@ public function testFailingGenerateWithOutputContainingPharPrefix(): void
$media->generate('the_input_file', 'phar://the_output_file', ['foo' => 'bar']);
}

public function testFailingGenerateWithOutputContainingUppercasePharPrefix(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
'configure',
'prepareOutput',
])
->setConstructorArgs(['the_binary', [], ['PATH' => '/usr/bin']])
->getMock()
;

$media->setTimeout(2000);

$media
->expects($this->once())
->method('prepareOutput')
->with($this->equalTo('PHAR://the_output_file'))
;

$this->expectException(InvalidArgumentException::class);

$media->generate('the_input_file', 'PHAR://the_output_file', ['foo' => 'bar']);
}

/**
* @return null|string
*/
Expand Down

0 comments on commit 8d893a8

Please sign in to comment.