Summary
patool before 4.0.6 may allow OS command injection on Windows when crafted archive filenames are incorporated into commands executed through cmd.exe. An attacker who can supply or influence filenames processed in supported single-file formats could execute commands with the privileges of the patool process.
patool before 4.0.6 may allow OS command injection on Windows when crafted archive filenames are incorporated into commands executed through cmd.exe. An attacker who can supply or influence filenames processed in supported single-file formats could execute commands with the privileges of the patool process.
Affected context
The issue can occur in Windows deployments of patool that process attacker-controlled archive filenames and invoke external commands with shell execution enabled. Risk is higher when the filename reaches a command-building path where Windows shell metacharacters or embedded double quotes are not safely escaped.
The issue can occur in Windows deployments of patool that process attacker-controlled archive filenames and invoke external commands with shell execution enabled. Risk is higher when the filename reaches a command-building path where Windows shell metacharacters or embedded double quotes are not safely escaped.
Exploit preconditions
- Attack surface: Windows command execution performed by patool during archive processing
- Required access: Ability to provide or influence an archive filename processed by patool
- Trigger point: Handling of a filename for a supported single-file archive format when the command is run with shell execution enabled
- Why exploitation is possible: The Windows quoting routine does not sufficiently escape cmd.exe metacharacters or embedded double quotes, allowing filename content to alter command interpretation
- Attack surface: Windows command execution performed by patool during archive processing
- Required access: Ability to provide or influence an archive filename processed by patool
- Trigger point: Handling of a filename for a supported single-file archive format when the command is run with shell execution enabled
- Why exploitation is possible: The Windows quoting routine does not sufficiently escape cmd.exe metacharacters or embedded double quotes, allowing filename content to alter command interpretation
Why this happens
The vulnerability results from incomplete Windows shell argument escaping in shell_quote_nt. Characters with control meaning to cmd.exe, including command separators and redirection operators, can remain active when a filename is incorporated into a shell command. This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because externally influenced data is passed to a command interpreter without reliable neutralization.
The vulnerability results from incomplete Windows shell argument escaping in shell_quote_nt. Characters with control meaning to cmd.exe, including command separators and redirection operators, can remain active when a filename is incorporated into a shell command. This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because externally influenced data is passed to a command interpreter without reliable neutralization.
Potential impact
- An attacker may execute arbitrary operating-system commands
- The patool process and its accessible files may be compromised
- Sensitive data may be read, modified, or deleted
- Malicious software could be installed using the process account's privileges
- Compromise could spread to connected systems or workflows depending on deployment permissions
- An attacker may execute arbitrary operating-system commands
- The patool process and its accessible files may be compromised
- Sensitive data may be read, modified, or deleted
- Malicious software could be installed using the process account's privileges
- Compromise could spread to connected systems or workflows depending on deployment permissions
General mitigation guidance
Mitigation generally focuses on eliminating shell interpretation and reducing trust in archive metadata.
Common defensive patterns include:
- Prefer direct process execution with argument arrays instead of
shell=True - Use a well-tested platform-specific quoting routine when shell invocation cannot be avoided
- Treat archive filenames and other metadata as untrusted input
- Apply strict filename validation and reject unexpected command metacharacters where appropriate
- Run archive processing with least-privilege accounts and restricted filesystem access
- Isolate archive extraction and conversion workloads from sensitive services
- Apply resource, filesystem, and network restrictions to processing workers
Mitigation generally focuses on eliminating shell interpretation and reducing trust in archive metadata.
Common defensive patterns include:
- Prefer direct process execution with argument arrays instead of
shell=True - Use a well-tested platform-specific quoting routine when shell invocation cannot be avoided
- Treat archive filenames and other metadata as untrusted input
- Apply strict filename validation and reject unexpected command metacharacters where appropriate
- Run archive processing with least-privilege accounts and restricted filesystem access
- Isolate archive extraction and conversion workloads from sensitive services
- Apply resource, filesystem, and network restrictions to processing workers
How teams detect issues like this
Organizations can look for:
- Static-analysis findings involving
shell=True, string-based command construction, and concatenation of archive metadata into commands - Code-review signals such as custom shell-quoting helpers or platform-specific escaping without comprehensive metacharacter handling
- Tests using adversarial filenames containing command separators, redirection characters, substitutions, and embedded quotes
- Runtime monitoring for unexpected child processes, command interpreters, or network connections spawned by archive-processing services
- Policy enforcement that blocks shell execution for untrusted input and requires approved process-launch APIs
Automated code-review and software-composition tools may help identify related command-injection patterns.
Organizations can look for:
- Static-analysis findings involving
shell=True, string-based command construction, and concatenation of archive metadata into commands - Code-review signals such as custom shell-quoting helpers or platform-specific escaping without comprehensive metacharacter handling
- Tests using adversarial filenames containing command separators, redirection characters, substitutions, and embedded quotes
- Runtime monitoring for unexpected child processes, command interpreters, or network connections spawned by archive-processing services
- Policy enforcement that blocks shell execution for untrusted input and requires approved process-launch APIs
Automated code-review and software-composition tools may help identify related command-injection patterns.

