Summary
textract versions through 2.5.0 contain an OS command injection flaw where user-controlled file paths are passed directly into shell execution.
An attacker who can influence the filename or file path being processed may execute arbitrary system commands with the privileges of the textract process.
Affected context
This vulnerability affects applications that use textract (through version 2.5.0) to process documents, images, or other files where filenames or file paths can be influenced by external input.
The issue resides in multiple extractors (e.g., DOC, RTF, DXF, images) and utility code that call child_process.exec() with file paths derived from incoming data.
Risk is elevated in web services, APIs, or batch processors that accept user-supplied uploads or paths without robust normalization and validation.
Exploit preconditions
- Attack surface: Any interface that ultimately passes a filename or file path into textract for processing (web upload endpoints, CLI wrappers, message queue workers, etc.).
- Required access: Ability to supply or control the name/location of a file that textract is asked to extract text from.
- Trigger point: Invocation of affected extractors (e.g., DOC, RTF, DXF, images) where the
filePathparameter is constructed from untrusted input. - Why exploitation is possible: The
filePathstring is interpolated directly into shell commands viachild_process.exec()with inadequate sanitization, allowing shell metacharacters and command sequences to be interpreted and executed by the OS.
Why this happens
The underlying bug is an instance of OS command injection, aligned with CWE-94 where dynamically constructed commands are built from untrusted data.
Instead of treating the file path purely as data passed to an argument-safe API, the code composes command strings that embed the path directly and executes them via child_process.exec(), which invokes a shell.
Because there is insufficient validation, escaping, or use of safer process-spawning primitives, an attacker can inject additional shell syntax into the path, causing unintended commands to run.
This reflects the insecure pattern of mixing user-controlled input with executable command strings without strictly constraining or separating data from code.
Potential impact
- Execution of arbitrary OS commands with the privileges of the textract-running service or user account
- Full compromise of the host running textract, including installation of malware or backdoors
- Unauthorized access, modification, or exfiltration of application and system data
- Pivoting to other internal services or infrastructure reachable from the compromised host
- Interference with normal service operation, including denial-of-service and data corruption
General mitigation guidance
Effective mitigation focuses on eliminating command construction from untrusted data and tightening trust boundaries around file handling:
- Prefer process-spawning APIs that do not invoke a shell (e.g.,
spawn/execFile-style calls with argument arrays) so that paths are treated strictly as data. - Avoid building shell command strings from file paths; if shell utilities are unavoidable, constrain inputs to a minimal, validated character set and avoid shell metacharacters entirely.
- Apply strong input validation and normalization for all filenames and paths before they reach textract, rejecting or sanitizing unexpected patterns such as embedded shell operators, newlines, or control characters.
- Isolate document-processing components with least-privilege OS accounts, constrained filesystem permissions, and sandboxing or containerization to reduce blast radius if a flaw is present.
- Design upload and processing workflows so that external users never control raw command fragments or environment details, and treat all file-related input as untrusted by default.
How teams detect issues like this
Organizations can identify and monitor this class of issue using:
- Static analysis rules that flag uses of
child_process.exec()and similar shell-invoking APIs where arguments are derived from request parameters, upload paths, or other untrusted sources. - Code review practices that highlight any dynamic command-string construction, especially in utility modules and file-processing pipelines, and require explicit justification or refactoring to safer patterns.
- Security linters or SAST tools configured to recognize OS command injection patterns (e.g., concatenation or template literals combining user input with shell commands).
- Runtime logging and monitoring for anomalous command executions originating from textract-related services, including unexpected binaries, network tooling, or atypical arguments.

