/

CVE-2026-26832

Severity:

CRITICAL RISK

(9.8)

OS Command Injection in node-tesseract-ocr recognize()

CVE-2026-26832

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Arbitrary Command Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

node-tesseract-ocr's recognize() function builds a shell command by concatenating the provided file path directly into a command string and executing it with child_process.exec().

If an attacker can influence the file path argument, they can inject additional shell metacharacters and commands, leading to arbitrary command execution with the privileges of the Node.js process.

Affected context

This vulnerability affects applications that use node-tesseract-ocr (through version 2.2.1) and pass user-controlled or otherwise untrusted values to the recognize() function.

The issue occurs because the file path parameter is used to construct a shell command for Tesseract and is passed to child_process.exec() without neutralizing shell metacharacters.

It becomes most risky in web services, APIs, CLIs, or background workers where request parameters, job payloads, or data from external systems flow into recognize() without strict validation and canonicalization.

Exploit preconditions

  • Attack surface: Any code path that calls recognize(filePath, ...) with data influenced by users, external services, or untrusted sources.
  • Required access: Ability to control or partially control the string passed as the file path argument (e.g., HTTP request parameter, form field, message payload, or configuration data).
  • Trigger point: Invocation of recognize() in src/index.js, which constructs a command string and executes it via child_process.exec().
  • Why exploitation is possible: The implementation performs string concatenation into a shell command without escaping or validating special characters, allowing the attacker to break out of the intended command and append arbitrary shell syntax.

Why this happens

The root cause is the direct construction of shell commands from untrusted input, which maps to CWE-78: Improper Neutralization of Special Elements Used in an OS Command ('OS Command Injection').

In this pattern, the wrapper code builds a Tesseract command by concatenating the supplied file path into a single command string and passes it to child_process.exec(), which invokes a shell.

Because no robust input validation, character whitelisting, or argument escaping is applied, shell metacharacters embedded in the file path are interpreted as part of the command, turning data into executable instructions.

This is an archetypal example of unsafe command execution APIs combined with direct string interpolation of untrusted data.

Potential impact

  • Execution of arbitrary system commands with the privileges of the Node.js process.
  • Reading, modifying, or deleting files accessible to the application user account.
  • Establishing reverse shells or downloading and executing additional malware.
  • Pivoting to other internal services or hosts reachable from the compromised environment.
  • Exfiltration of sensitive information such as environment variables, credentials, or API keys.
  • Full compromise of the host or container when the process runs with high privileges or has broad file/system access.

General mitigation guidance

Effective mitigation focuses on eliminating direct shell command construction and reducing trust in input that reaches execution boundaries.

Recommended defensive patterns include:

  • Prefer parameterized, non-shell execution APIs: use child_process.execFile(), spawn(), or similar variants that pass arguments as arrays and avoid going through the shell when invoking Tesseract.
  • Treat file paths as data, not code: never interpolate user input directly into a command string; use explicit argument lists and avoid dynamic shell syntax altogether.
  • Apply strict validation and normalization on file paths: constrain inputs to expected formats (e.g., filenames without spaces or metacharacters), enforce whitelists, limit to known directories, and reject any unexpected characters or patterns.
  • Enforce least privilege: run the Node.js process and underlying OCR tooling with minimal filesystem and network permissions, and drop unnecessary privileges so that a successful injection yields limited impact.
  • Isolate execution: where possible, confine OCR processing to a sandboxed context (e.g., container with restricted capabilities, chroot, or dedicated worker with reduced access).

How teams detect issues like this

Detection typically involves surfacing unsafe command construction patterns and monitoring for anomalous command execution behavior.

High-level strategies include:

  • Static analysis rules that flag uses of child_process.exec(), execSync(), or similar APIs when user-controlled variables appear in the command string, especially concatenations or template literals.
  • Code review checklists that explicitly require reviewers to inspect any shell invocation wrapper, ensuring no direct interpolation of user input into commands.
  • Grep- or AST-based searches in CI pipelines for command-execution hot spots, combined with security policies that require justification or refactoring away from shell-based APIs.
  • Runtime monitoring and logging of executed commands, with alerts for unexpected arguments, shell metacharacters, or command patterns that deviate from known Tesseract invocation templates.
  • Integration of SAST/IAST tools capable of taint tracking from external inputs into command execution sinks.

Sources

SourceLink
github.comgithub.com/zapolnoch/node-tesseract-ocr
github.comgithub.com/zapolnoch/node-tesseract-ocr/blob/master/src/index.js
github.comgithub.com/zebbernCVE/CVE-2026-26832
npmjs.comnpmjs.com/package/node-tesseract-ocr

Frequently asked

questions

Yes, it can be remotely exploitable whenever a remote user or system can influence the value passed to recognize(), such as via HTTP parameters, uploaded file names, or message payloads. In such cases, an attacker may trigger command injection over the network.

The attacker needs the ability to supply or manipulate the file path parameter that flows into recognize(). No direct shell or OS access is required; access is at the application input level (e.g., web request, API call, or job configuration).

The safest pattern is to avoid shell-based execution entirely for OCR calls by using APIs like execFile() or spawn() with argument arrays, ensuring the file path is passed as a separate argument, not embedded in a shell command string, and combining that with strict input validation and normalization.

Adopt a development standard that prohibits direct interpolation of untrusted data into command strings, treat any command execution as a sensitive sink in code review, rely on non-shell execution APIs by default, and enforce automated checks (linting, SAST) that flag unsafe use of child_process.exec() and equivalent functions.

Find out what's already
exploitable in your codebase.