Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
endelwar committed Apr 26, 2023
2 parents d7b19c2 + 086badf commit ae8bc11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning(https://semver.org/spec/v2.0.0.

## Unreleased

## 1.1.1 - 2023-04-27
### Security
- Implement countermeasures for CVE-2023-28115

## 1.1.0 - 2023-04-03
### Added
- Support WeasyPrint 58 new option (--pdf-forms)
Expand Down
4 changes: 4 additions & 0 deletions src/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ protected function executeCommand(string $command): array
*/
protected function prepareOutput(string $filename, bool $overwrite): void
{
if (0 === \strpos($filename, 'phar://')) {
throw new \InvalidArgumentException('The output file cannot be a phar archive.');
}

$directory = \dirname($filename);

if ($this->fileExists($filename)) {
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,4 +907,32 @@ private function getPHPExecutableFromPath(): ?string

return null; // not found
}

/**
* test against CVE-2023-28115
* fix and test by @AntoineLelaisant
*/
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']);
}
}

0 comments on commit ae8bc11

Please sign in to comment.