/

CVE-2026-11526

Severity:

CRITICAL RISK

(9.8)

OS Command Injection (CWE-78) in Perl GD File Handling

CVE-2026-11526

Deferred

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-73, CWE-78

Impact:

Remote Code Execution and Arbitrary File Overwrite

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

Perl GD versions before 2.86 contain an OS command injection flaw in the _make_filehandle helper used by all file-based image constructors.

When untrusted filenames are passed into methods like newFromPng or newFromJpeg, specially crafted values can execute arbitrary commands or overwrite files under the process UID.

Affected context

The vulnerability arises in applications that use Perl GD (before 2.86) and pass attacker-controlled or partially untrusted strings as filenames to image constructors such as GD::Image->new, newFromPng, newFromJpeg, and similar file-based methods.

It specifically affects the code path that converts these filename arguments into filehandles via _make_filehandle, which relies on Perl's 2-argument open() semantics.

Deployments that only use the in-memory *Data variants (e.g., newFromPngData) and never interpret untrusted data as a filesystem path are not directly exposed to this bug.

Exploit preconditions

  • Attack surface: Any API endpoint, script, or background job that accepts user input and passes it—directly or indirectly—as a filename to GD image constructors.
  • Required access: Ability to influence or control the path string passed into GD::Image::_make_filehandle (for example via HTTP parameters, uploaded metadata, form fields, job configuration, or message payloads).
  • Trigger point: Invocation of a GD constructor that takes a filename (e.g., GD::Image->new("user_value"), newFromPng("user_value")), which internally calls _make_filehandle.
  • Why exploitation is possible: _make_filehandle uses Perl's 2-arg open() with the filename string, so filenames starting or ending with a pipe ("| cmd", "cmd |") or starting with redirection syntax ("> path", ">> path") are interpreted by Perl as shell commands or redirection targets instead of literal file paths.

Why this happens

The core issue is reliance on Perl's 2-argument open() with attacker-influenced strings, which conflates file path interpretation with shell-like command execution and redirection.

Under this model, a "filename" that begins or ends with a pipe character is treated as a command to execute, and leading > or >> denotes redirection targets, allowing arbitrary command execution or file truncation/overwrite.

This behavior maps primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because special shell metacharacters in untrusted input are not neutralized or removed before being passed to open().

It is also related to CWE-73: External Control of File Name or Path, since external input controls a file-or-command string that the library assumes to be a plain filename.

Potential impact

  • Attackers can execute arbitrary OS commands under the privileges of the process running Perl GD.
  • Files can be truncated or overwritten (e.g., log files, configuration files, temporary data) via redirection-like filename patterns.
  • Compromise of the hosting application, including theft or corruption of data handled by the process.
  • Lateral movement or further privilege escalation if combined with other local misconfigurations.
  • Service disruption, denial of service, or environmental instability due to destructive commands or file corruption.

General mitigation guidance

Effective mitigation centers on strict separation between filenames and commands, and on reducing trust in any externally derived path string.

Recommended defensive patterns include:

  • Avoid passing untrusted or semi-trusted input directly as filenames to GD constructors; instead, map user input to a vetted whitelist of server-side paths or use generated temporary filenames.
  • Prefer in-memory *Data variants (e.g., newFromPngData, newFromJpegData) when handling user-supplied image content, so raw user data is never interpreted as a filesystem path.
  • Sanitize and validate all filenames by rejecting values containing shell metacharacters such as |, >, <, &, ;, and newline characters, and enforce strict patterns for allowable filenames.
  • Use safer file-opening idioms that do not invoke shell semantics (e.g., 3-argument open() with explicit mode and no shell interpretation) in any wrapper or utility code around GD.
  • Run the application under the least-privileged account possible, with restricted filesystem write access and constrained execution environment to limit damage if a path-handling bug is reached.

How teams detect issues like this

Detection typically involves both code-level analysis and runtime monitoring:

  • Static analysis: Search for usage of GD image constructors that accept filenames in code paths reachable by user input, especially where raw parameters or request fields are passed directly as arguments.
  • Pattern-based scans: Flag any internal helper functions that call 2-argument open() with variables influenced by external data; enforce policies that require 3-argument open() or equivalent safe patterns.
  • Code review: Examine file handling and image loading logic for assumptions that filenames are "safe," focusing on areas where user data is cast to a filesystem path or where path normalization is missing.
  • Runtime monitoring: Use logging or application-level security controls to detect suspicious filename values containing pipes or redirection characters, and to alert on unexpected command executions or file truncations.
  • Automated code review tools and SAST platforms can be configured with custom rules to spot Perl 2-arg open() and untrusted path flows specifically in GD-related code paths.

Sources

SourceLink
github.comgithub.com/lstein/Perl-GD/commit/67b163713c6c78dfeb693da0978ae934e5cd8210.patch
metacpan.orgmetacpan.org/release/RURBAN/GD-2.86/changes
openwall.comopenwall.com/lists/oss-security/2026/06/14/4
lists.debian.orglists.debian.org/debian-lts-announce/2026/06/msg00027.html

Frequently asked

questions

Yes, in typical web or networked applications that expose GD-based image processing as part of their functionality. If a remote attacker can influence the filename passed to GD constructors, they can often trigger command execution or file overwrite over the network.

The attacker needs the ability to control or significantly influence the string used as the filename argument to GD's file-based constructors. This might be via HTTP parameters, form fields, configuration options, or any other input channel that is ultimately forwarded to GD::Image->_make_filehandle.

The safest pattern is to eliminate the use of untrusted data as filenames: convert user data into in-memory image streams (*Data variants), rely on server-generated filenames, and ensure that any file opening uses safe APIs (like 3-argument open()) that do not interpret shell metacharacters. Additionally, validate and restrict any remaining filename inputs to a narrow set of allowed patterns.

Preventive strategies include adopting secure coding guidelines for file and process handling, banning dangerous primitives like 2-arg open() in code review, validating and normalizing all externally influenced paths, and enabling automated scans that flag command injection and unsafe file API usage. Treat any string that originated outside the process as untrusted, especially when it will be used in file operations or passed to the operating system.

Find out what's already
exploitable in your codebase.