Summary
An OS command injection vulnerability in the app.py component of openlabs docker-wkhtmltopdf-aas allows crafted POST requests to influence shell command execution within the container.
When user-controlled HTTP parameters are passed into command-line invocations without proper sanitization or escaping, an attacker may execute arbitrary system commands with the service's privileges.
Affected context
This vulnerability affects deployments of the docker-wkhtmltopdf-aas service up to commit 9f50579 where HTTP request data is used to construct command-line calls to wkhtmltopdf or related utilities.
It is most relevant in environments where:
- The app.py HTTP API is exposed over a network
- Clients can submit arbitrary or semi-structured POST bodies
- The service runs with permissions that grant meaningful access to the filesystem or other internal services
The issue is triggered during request handling when user input is interpolated into shell commands rather than passed as strictly validated arguments.
Exploit preconditions
- Attack surface: Network-exposed HTTP endpoint accepting POST requests (e.g., a PDF-as-a-service API).
- Required access: Ability to send POST requests to the vulnerable service; no local access is required if the service is reachable over the network.
- Trigger point: Parameters in the POST body that are used to construct or influence shell commands, such as URLs, options, or filenames.
- Why exploitation is possible: User-controlled data is concatenated into command strings or passed through shells without robust validation, quoting, or strict argument whitelisting, allowing injection of additional shell metacharacters and commands.
Why this happens
The underlying issue is improper handling of untrusted input in OS command construction, corresponding to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
In app.py, input from HTTP POST requests is likely integrated into command-line strings used to invoke wkhtmltopdf or related tools, either via shell=True, direct concatenation, or template-style command assembly.
Because the code treats user input as text to be appended to a shell command rather than as data passed through a safe, argument-based API, attackers can introduce shell metacharacters, inject additional arguments, or chain arbitrary commands that the shell will interpret and execute.
Potential impact
- Remote execution of arbitrary commands inside the container or host environment (depending on isolation).
- Reading, modifying, or deleting files accessible to the service account.
- Pivoting to other internal services reachable from the container network.
- Downloading and running malware or backdoors from external locations.
- Using the service as a foothold for broader infrastructure compromise or data exfiltration.
General mitigation guidance
Effective mitigation focuses on removing the ability for user input to alter shell interpretation and on tightening the execution environment:
- Prefer APIs that construct commands as argument lists (e.g., exec-style calls) instead of shell-based command strings.
- Enforce strict, allowlist-based validation for all user-supplied parameters that influence command execution (e.g., limited flags, known-safe URLs or formats).
- Reject or normalize inputs containing shell metacharacters, control operators, or unexpected whitespace expansions.
- Separate user-controlled data from executable logic by mapping high-level request options to fixed, pre-defined command templates and argument sets.
- Run the service with least-privilege accounts and minimal filesystem and network access to limit the impact of any compromise.
- Consider isolating the wkhtmltopdf execution in a further restricted sandbox or worker process with constrained capabilities.
How teams detect issues like this
Detection typically combines code-centric and runtime approaches:
- Static analysis: Configure rules or linters to flag uses of shell=True, system(), popen(), or similar APIs where arguments include web request parameters or other untrusted sources.
- Code review: Look for string concatenation or formatting that mixes request fields with command strings, and for missing validation or allowlists around command-related parameters.
- Security testing: Use dynamic application security testing (DAST) or manual testing with benign command injection patterns in POST bodies to observe unexpected behavior.
- Runtime monitoring: Inspect logs and command audit trails for anomalous arguments or shell metacharacters, and monitor containers for unusual process trees or outbound network connections.
- Policy enforcement: Incorporate secure coding policies into CI pipelines to prevent merging patterns that construct shell commands from untrusted input.

