/

CVE-2026-42589

Severity:

CRITICAL RISK

(9.8)

Command Injection in Gotenberg PDF Metadata API

CVE-2026-42589

Analyzed

Vulnerability type

Category:

Command Injection

CWE:

CWE-78

Impact:

Unauthenticated Remote Code Execution via Command Injection

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

Gotenberg's /forms/pdfengines/metadata/write endpoint builds ExifTool command input directly from user-supplied JSON metadata keys without validating special characters.

By embedding newline characters in metadata keys, an attacker can inject arbitrary ExifTool flags that evaluate Perl expressions, leading to unauthenticated OS command execution via a single HTTP request that still returns a valid PDF response.

Affected context

This vulnerability affects deployments of Gotenberg that expose the /forms/pdfengines/metadata/write HTTP endpoint and rely on ExifTool for PDF metadata handling.

It manifests when JSON metadata provided by clients is passed through the go-exiftool library directly to ExifTool's stdin without sanitizing or constraining metadata key names.

Any environment where this endpoint is reachable over the network, including internal service meshes or public-facing APIs, can be at risk if metadata keys are treated as trusted input.

Exploit preconditions

  • Attack surface: Gotenberg HTTP API, specifically POST /forms/pdfengines/metadata/write.
  • Required access: Network access to the vulnerable endpoint; no authentication is required in a typical configuration.
  • Trigger point: Submission of a crafted JSON body where one or more metadata keys contain an embedded newline (\n) followed by additional ExifTool options.
  • Why exploitation is possible: The service constructs ExifTool input by inserting metadata keys verbatim into the stdin stream. Because newline characters are not filtered, they terminate the current argument line and start a new one, effectively injecting arbitrary ExifTool flags (including those that can evaluate Perl expressions and execute OS commands).

Why this happens

The core issue is a command injection pattern where user-controlled data is treated as part of a command-line interface without proper encoding or validation.

In this case, metadata keys from JSON are assumed to be harmless labels but are passed directly into ExifTool's stdin protocol, which interprets line breaks and options as control syntax.

This aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command, as untrusted input containing special characters (\n and ExifTool flag syntax) breaks out of the intended data context, becoming executable ExifTool options that can lead to OS command execution via Perl expression evaluation.

Potential impact

  • Execution of arbitrary OS commands with the privileges of the Gotenberg service process.
  • Complete compromise of the container or host running Gotenberg, depending on isolation and hardening.
  • Unauthorized access to files readable by the Gotenberg process, including sensitive documents or configuration.
  • Use of the Gotenberg instance as a pivot point for lateral movement within the network.
  • Covert exploitation that returns HTTP 200 along with a valid PDF, evading basic uptime or error-based monitoring.

General mitigation guidance

Effective mitigation typically focuses on strictly separating user input from command semantics and constraining how external tools are invoked:

  • Treat metadata keys as data only and enforce normalization rules (e.g., allowlists for allowed characters, length limits, and rejection of control characters such as newlines).
  • Use structured APIs or libraries that model ExifTool options explicitly, rather than passing user input directly into argument or stdin streams.
  • Apply robust input validation at the HTTP boundary, rejecting requests whose metadata keys contain control characters, whitespace beyond simple spaces, or shell-like constructs.
  • Run ExifTool and the Gotenberg service with least privilege, in isolated containers or sandboxes, to reduce the blast radius if injection occurs.
  • Prefer safe-by-design patterns where user-supplied metadata is serialized into well-defined, escaped fields that cannot be interpreted as tool flags.

How teams detect issues like this

High-level detection often combines code inspection with behavioral monitoring:

  • Static analysis and code review:
  • Flag any code paths that interpolate user-controlled metadata keys into command arguments or stdin streams for external tools.
  • Look for uses of wrappers around ExifTool (such as go-exiftool) where raw user input is converted into ExifTool options without explicit validation.
  • Review validation logic around metadata keys for missing checks on control characters (\n, \r, tabs) and special flag syntax.
  • Runtime and log analysis:
  • Monitor ExifTool invocation logs or audit trails for unexpected flags, especially those enabling expression evaluation or non-standard behavior.
  • Inspect API logs for metadata keys containing control characters, multi-line content, or suspicious patterns resembling command options.
  • Security policy enforcement:
  • Integrate automated review tools in CI pipelines to enforce input sanitation policies and disallow unescaped insertion of user input into external tool interfaces.
  • Use container and host-level monitoring to detect anomalous process activity stemming from the Gotenberg service.

Sources

SourceLink
github.comgithub.com/gotenberg/gotenberg/security/advisories/GHSA-rqgh-gxv4-6657

Frequently asked

questions

Yes. An attacker who can send HTTP requests to the /forms/pdfengines/metadata/write endpoint can exploit the issue remotely by crafting malicious JSON metadata, without needing interactive access to the host.

In typical configurations where this endpoint is not access-controlled, no authentication is required. The primary requirement is network reachability to the vulnerable Gotenberg instance.

The safest pattern is to ensure user input never influences command semantics. This means strictly validating and normalizing metadata keys (e.g., allowlisting characters, rejecting control characters), using structured APIs for external tools, and avoiding any direct translation of user input into command-line flags or control directives.

Prevention focuses on design-time and implementation-time safeguards: avoid constructing commands from raw user input, apply rigorous input validation and encoding, encapsulate external tool invocations behind well-defined interfaces, and include security-focused code review and automated checks that highlight any path where untrusted data reaches command or tool invocation layers.

Find out what's already
exploitable in your codebase.