CVE-2023-28115 (published 2023-03-17T22:15Z)

Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Prior to version 1.4.2, Snappy is vulnerable to PHAR deserialization due to a lack of checking on the protocol before passing it into the `file_exists()` function. If an attacker can upload files of any type to the server he can pass in the phar:// protocol to unserialize the uploaded file and instantiate arbitrary PHP objects. This can lead to remote code execution especially when snappy is used with frameworks with documented POP chains like Laravel/Symfony vulnerable developer code. If a user can control the output file from the `generateFromHtml()` function, it will invoke deserialization. This vulnerability is capable of remote code execution if Snappy is used with frameworks or developer code with vulnerable POP chains. It has been fixed in version 1.4.2.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-502
cwe_name: Deserialization of Untrusted Data
description: The product deserializes untrusted data without sufficiently verifying that the resulting data will be valid.
extended_description: 
            It is often convenient to serialize objects for communication or to save them for later use. However, deserialized data or code can often be modified without using the provided accessor functions if it does not use cryptography to protect itself. Furthermore, any cryptography would still be client-side security -- which is a dangerous security assumption.
            Data that is untrusted can not be trusted to be well-formed.
            When developers place no restrictions on "gadget chains," or series of instances and method invocations that can self-execute during the deserialization process (i.e., before the object is returned to the caller), it is sometimes possible for attackers to leverage them to perform unauthorized actions, like generating a shell.
         
         

Fix information:
repo_url: https://github.com/KnpLabs/snappy
commit_details: repo_url: https://github.com/KnpLabs/snappy
author: Antoine Lelaisant
author_date: 2023-03-17 15:47:54+01:00
msg: Merge pull request #469 from KnpLabs/fix/GHSA-gq6w-q6wh-jggc

fix: security issue GHSA-gq6w-q6wh-jggc
repository: repo_url: https://github.com/KnpLabs/snappy
repo_name: KnpLabs/snappy
description: PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
repo_language: PHP
owner: KnpLabs
repo_url: https://github.com/KnpLabs/snappy
commit_details: repo_url: https://github.com/KnpLabs/snappy
author: Antoine Lelaisant
author_date: 2023-03-17 15:38:20+01:00
msg: fix: security issue GHSA-gq6w-q6wh-jggc
repository: repo_url: https://github.com/KnpLabs/snappy
repo_name: KnpLabs/snappy
description: PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
repo_language: PHP
owner: KnpLabs
file_changes: filename: AbstractGenerator.php
change_type: ModificationType.MODIFY
diff: @@ -625,6 +625,10 @@ abstract class AbstractGenerator implements GeneratorInterface, LoggerAwareInter
      */
     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)) {

programming_language: PHP
filename: AbstractGeneratorTest.php
change_type: ModificationType.MODIFY
diff: @@ -938,6 +938,30 @@ class AbstractGeneratorTest extends TestCase
         );
     }
 
+    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
      */

programming_language: PHP