/

CVE-2026-107704

Severity:

CRITICAL RISK

(9.8)

OS Command Injection (CWE-78) in image_optimizer Gem

CVE-2026-107704

Deferred

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

The image_optimizer Ruby gem contains an OS command injection vulnerability in its image-format identification logic. When the gem processes an attacker-controlled image path with the identify option enabled, crafted path data may cause arbitrary commands to run with the privileges of the Ruby process.

The image_optimizer Ruby gem contains an OS command injection vulnerability in its image-format identification logic. When the gem processes an attacker-controlled image path with the identify option enabled, crafted path data may cause arbitrary commands to run with the privileges of the Ruby process.

Affected context

The vulnerability occurs in applications using image_optimizer versions 1.3.0 through 1.9.0 when the identify option is enabled and image paths can be influenced by an untrusted party. Common exposure scenarios may include uploaded files, user-supplied filenames, or other paths that reach ImageOptimizer#identify_format without adequate neutralization.

The vulnerability occurs in applications using image_optimizer versions 1.3.0 through 1.9.0 when the identify option is enabled and image paths can be influenced by an untrusted party. Common exposure scenarios may include uploaded files, user-supplied filenames, or other paths that reach ImageOptimizer#identify_format without adequate neutralization.

Exploit preconditions

  • Attack surface: Image processing functionality that invokes ImageOptimizer#identify_format
  • Required access: Ability to influence an image path or uploaded file name
  • Trigger point: Image-format identification while the identify option is enabled
  • Why exploitation is possible: The path is incorporated into a shell command executed through Ruby backtick syntax, allowing shell metacharacters in untrusted input to alter command interpretation
  • Attack surface: Image processing functionality that invokes ImageOptimizer#identify_format
  • Required access: Ability to influence an image path or uploaded file name
  • Trigger point: Image-format identification while the identify option is enabled
  • Why exploitation is possible: The path is incorporated into a shell command executed through Ruby backtick syntax, allowing shell metacharacters in untrusted input to alter command interpretation

Why this happens

The underlying bug is the construction and execution of a shell command using attacker-influenced path data without reliable argument separation or shell-safe handling. Ruby backticks invoke a command shell, so special characters in the supplied path can be interpreted as shell syntax rather than ordinary filename content. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, commonly known as OS command injection.

The underlying bug is the construction and execution of a shell command using attacker-influenced path data without reliable argument separation or shell-safe handling. Ruby backticks invoke a command shell, so special characters in the supplied path can be interpreted as shell syntax rather than ordinary filename content. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, commonly known as OS command injection.

Potential impact

  • An attacker may execute arbitrary operating-system commands
  • The application process and its accessible files may be compromised
  • Sensitive data may be disclosed or modified
  • Application credentials or service tokens could be exposed
  • The host or surrounding services may be affected, depending on process privileges and isolation
  • An attacker may execute arbitrary operating-system commands
  • The application process and its accessible files may be compromised
  • Sensitive data may be disclosed or modified
  • Application credentials or service tokens could be exposed
  • The host or surrounding services may be affected, depending on process privileges and isolation

General mitigation guidance

Mitigation generally focuses on removing shell interpretation from image-processing workflows and reducing trust in file paths.

Common defensive patterns include:

  • Use direct process-execution APIs with separate argument arrays instead of shell command construction
  • Treat uploaded filenames and paths as untrusted data
  • Generate server-side filenames and resolve files against controlled directories
  • Apply strict path validation, canonicalization, and allowlisting where appropriate
  • Disable optional external identification behavior when it is not required
  • Run image-processing workers with least privilege and restricted filesystem access
  • Limit network, credential, and operating-system permissions available to the Ruby process

Mitigation generally focuses on removing shell interpretation from image-processing workflows and reducing trust in file paths.

Common defensive patterns include:

  • Use direct process-execution APIs with separate argument arrays instead of shell command construction
  • Treat uploaded filenames and paths as untrusted data
  • Generate server-side filenames and resolve files against controlled directories
  • Apply strict path validation, canonicalization, and allowlisting where appropriate
  • Disable optional external identification behavior when it is not required
  • Run image-processing workers with least privilege and restricted filesystem access
  • Limit network, credential, and operating-system permissions available to the Ruby process

How teams detect issues like this

Organizations can identify similar command-injection risks through:

  • Static analysis rules for shell execution APIs, including Ruby backticks and equivalent process calls
  • Code review checks for user-controlled values reaching command strings
  • Searches for image-processing paths, filenames, or upload metadata passed to shell interpreters
  • Runtime monitoring of unexpected child processes spawned by image-processing workers
  • Policy enforcement requiring argument-separated process execution and approved executable paths

Automated code review and software composition analysis tools may help identify unsafe command construction and affected dependency usage.

Organizations can identify similar command-injection risks through:

  • Static analysis rules for shell execution APIs, including Ruby backticks and equivalent process calls
  • Code review checks for user-controlled values reaching command strings
  • Searches for image-processing paths, filenames, or upload metadata passed to shell interpreters
  • Runtime monitoring of unexpected child processes spawned by image-processing workers
  • Policy enforcement requiring argument-separated process execution and approved executable paths

Automated code review and software composition analysis tools may help identify unsafe command construction and affected dependency usage.

Sources

SourceLink
gist.github.comgist.github.com/R3tro16/a99a058d24a06692721a6a3fade9649d
github.comgithub.com/jtescher/image_optimizer
github.comgithub.com/jtescher/image_optimizer/blob/v1.9.0/lib/image_optimizer.rb#L37-L47
github.comgithub.com/jtescher/image_optimizer/blob/v1.9.0/lib/image_optimizer/shell.rb#L30-L32
vulncheck.comvulncheck.com/advisories/image-optimizer-1.3.0-through-1.9.0-os-command-injection-via-identify-format

Frequently asked

questions

It can be remotely exploitable when a network-facing application allows users to upload files or otherwise control image paths that reach the vulnerable image-identification function.

Authentication is deployment-dependent. The essential prerequisite is the ability to influence a processed image path, whether through an authenticated upload workflow or another exposed input.

Avoid shell interpretation entirely by invoking image-identification tools through safe, argument-separated APIs and by treating all filenames and paths as untrusted.

Use generated server-side filenames, enforce controlled-path validation, review all subprocess calls, and run image-processing components with minimal privileges and restricted access.

It can be remotely exploitable when a network-facing application allows users to upload files or otherwise control image paths that reach the vulnerable image-identification function.

Authentication is deployment-dependent. The essential prerequisite is the ability to influence a processed image path, whether through an authenticated upload workflow or another exposed input.

Avoid shell interpretation entirely by invoking image-identification tools through safe, argument-separated APIs and by treating all filenames and paths as untrusted.

Use generated server-side filenames, enforce controlled-path validation, review all subprocess calls, and run image-processing components with minimal privileges and restricted access.

Find out what's already
exploitable in your codebase.