Summary
Perl's HTTP::Daemon module prior to version 6.17 contains an OS command injection flaw in the send_file() helper, which passes its string argument directly to Perl's 2-argument open().
If untrusted data is used as the send_file() path, an attacker can trigger shell-style "magic" prefixes, execute arbitrary commands with the daemon's privileges, exfiltrate command output in HTTP responses, or create/overwrite files on the server.
Affected context
This vulnerability occurs in applications built on top of Perl's HTTP::Daemon that use the send_file() method with user-influenced values.
It is most relevant when:
- The HTTP server dynamically determines the argument to send_file() from request parameters, headers, or other untrusted sources.
- The daemon process runs with permissions that give access to sensitive files or system utilities.
- There is no sanitization or strict validation of the file paths or tokens passed into send_file().
In such contexts, the 2-argument open() call inside send_file() becomes an unintended command execution and file system primitive.
Exploit preconditions
- Attack surface: Remote HTTP endpoints that cause the server to call HTTP::Daemon::send_file().
- Required access: Ability to send crafted HTTP requests influencing the string passed to send_file() (e.g., path segments, query parameters, or other request-controlled values).
- Trigger point: Invocation of send_file($user_controlled_string), where the string is interpreted by Perl's 2-arg open() as:
- A command pipeline, e.g., "| cmd" or "cmd |"
- A write or append target, e.g., "> path" or ">> path"
- Why exploitation is possible: Perl's 2-arg open() treats certain leading characters as directives to spawn subprocesses or open file handles with specific modes.
send_file() forwards its argument directly into this API without enforcing a neutral file-open mode or stripping special prefixes, enabling untrusted input to control process creation and file operations.
Why this happens
The underlying issue is the use of Perl's 2-argument open() with user-influenced data, an insecure pattern that blends data with control instructions.
In this pattern, a seemingly benign "file name" string is overloaded to encode shell-like behavior:
- Strings starting with "|" or ending with "|" create pipes to subprocesses.
- Strings starting with ">" or ">>" open files for write or append.
HTTP::Daemon::send_file() relies on this 2-arg open() signature without constraining its semantics, which maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command and, due to unintended control of filesystem targets, also relates to CWE-73: External Control of File Name or Path.
Conceptually, the bug is that the API treats untrusted "file" input as executable instructions, violating the principle of strict separation between data and command channels.
Potential impact
- Remote execution of arbitrary OS commands under the daemon process UID.
- Inclusion of subprocess stdout directly into HTTP responses ("cmd |" behavior), enabling data exfiltration or arbitrary content injection.
- Creation, truncation, or modification of files at attacker-controlled paths using write or append prefixes ("> path", ">> path").
- Potential overwrite of configuration, log, or application files, degrading integrity and availability.
- Use of file writes and command execution as building blocks for further privilege escalation or lateral movement within the environment.
General mitigation guidance
Effective mitigation focuses on removing command semantics from file-handling paths and strictly controlling filenames derived from external input.
General defensive patterns include:
- Avoiding APIs that overload their arguments with command or mode directives (e.g., Perl's 2-arg open()) when the argument can be influenced by user input; prefer safer alternatives (e.g., 3-arg open() or dedicated file APIs) that require explicit mode and treat the path as pure data.
- Implementing strict allowlists for file paths used in send_file()-like helpers, such as mapping request tokens to a predefined set of files or directories instead of passing raw user input.
- Normalizing and validating paths before use: reject any value that begins with or contains characters or patterns associated with pipes, redirections, or other special open() semantics.
- Running the HTTP daemon with the least privileges necessary, isolating it in a constrained account, chroot, or container to limit file-system and process-level blast radius.
- Separating static file serving from dynamic logic, using hardened, purpose-built components (e.g., a dedicated static file server) for untrusted file delivery paths.
How teams detect issues like this
Detection typically combines code-centric analysis with runtime and process-level observations:
- Static analysis: Search for usages of HTTP::Daemon::send_file() and Perl's 2-argument open() where the argument is derived from request parameters, environment variables, or other untrusted sources.
Flag patterns where the argument is not passed through an allowlist or rigorous validation.
- Code review signals: During manual review, pay attention to:
- Any send_file() calls that accept user input directly or via thin wrappers.
- open() calls with a single string argument that may contain "|", ">", or similar characters.
- File-serving logic that interpolates user-controlled tokens into path strings without canonicalization.
- Policy enforcement: Introduce project-wide guidelines or linters that:
- Disallow 2-arg open() in HTTP handling code or require explicit justification and review.
- Enforce patterns where file paths originate from safe enumerations, not raw input.
- Runtime monitoring: Observe process creation patterns from the daemon process, unexpected child processes, or sudden changes in server-owned files which may indicate exploitation attempts.

