Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: security issue GHSA-gq6w-q6wh-jggc #469

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ 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.');
}

$directory = \dirname($filename);

if ($this->fileExists($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 @@ -938,6 +938,30 @@ protected function configure(): void
);
}

public function testFailingGenerateWithOutputContainingPharPrefix(): 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