KnpLabs knp-snappy Command Injection Vulnerability (CVE-2026-46643)
KnpLabs knp-snappy versions 1.7.0 and earlier are vulnerable to command injection (CVE-2026-46643) due to an inverted is_executable check, which prevents proper shell escaping of the binary path, potentially leading to command execution if the binary path is attacker-influenced.
The KnpLabs knp-snappy library, a PHP wrapper for the wkhtmltopdf and wkhtmltoimage utilities, is susceptible to a command injection vulnerability (CVE-2026-46643) in versions 1.7.0 and earlier. The vulnerability arises from an incorrect implementation of input sanitization, specifically, an inverted is_executable check that causes the binary path to bypass shell escaping. This flaw can be exploited when the binary path is derived from user-influenced configuration, environment variables originating from request data, or concatenated with user-controlled fragments. An attacker can inject arbitrary commands into the binary path, leading to command execution on the server. This is a regression, since downstream packages reasonably assume Snappy shell-escapes the binary. The vulnerability was patched in version 1.7.1.
Attack Chain
- An attacker identifies a web application utilizing the vulnerable knp-snappy library (version 1.7.0 or earlier) to generate PDFs.
- The attacker determines that the path to the
wkhtmltopdfbinary is configurable via a user-controlled source (e.g., a configuration file or environment variable). - The attacker injects a malicious command into the binary path. For example, setting the binary path to
wkhtmltopdf; touch /tmp/snappy_rce. - The web application uses the knp-snappy library to generate a PDF, passing the attacker-controlled binary path to the
Knp\Snappy\Pdfconstructor. - Due to the flawed
is_executablecheck, the binary path is not properly shell-escaped. - The
wkhtmltopdfutility is invoked with the injected command. - The injected command is executed on the server with the privileges of the PHP process.
- The attacker achieves arbitrary command execution, potentially leading to further compromise of the system.
Impact
Successful exploitation of this vulnerability allows an attacker to execute arbitrary commands on the server hosting the vulnerable web application. The impact ranges from reading sensitive files and modifying application data to full system compromise, depending on the permissions of the PHP process. This vulnerability affects applications that rely on knp-snappy for PDF generation and where the binary path is sourced from a user-influenced location. Even if the binary path is hardcoded, this is a defensive-in-depth regression.
Recommendation
- Upgrade to knp-snappy version 1.7.1 or later to patch CVE-2026-46643.
- As a workaround, implement a check using
\is_executable($path)before calling theKnp\Snappy\Pdfconstructor to ensure the binary path is valid. - Deploy the Sigma rule “Detect knp-snappy Command Injection Attempt” to identify attempts to exploit this vulnerability by detecting shell metacharacters in process command lines.
- Review all instances where the
wkhtmltopdfbinary path is configured and ensure that user input is properly validated and sanitized to prevent command injection.
Detection coverage 2
Detect knp-snappy Command Injection Attempt
highDetects CVE-2026-46643 exploitation — attempts to exploit command injection in knp-snappy by detecting shell metacharacters in process command lines involving wkhtmltopdf
Detect knp-snappy Command Injection Attempt (Linux)
highDetects CVE-2026-46643 exploitation — attempts to exploit command injection in knp-snappy by detecting shell metacharacters in process command lines involving wkhtmltopdf on Linux
Detection queries are available on the platform. Get full rules →