/

CVE-2026-67986

Severity:

HIGH RISK

(8.4)

Ruby Code Injection (CWE-94) in amazing_print#grep

CVE-2026-67986

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Ruby Code Execution

Severity:

HIGH RISK

(8.4)

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

A Ruby code injection vulnerability in amazing_print can cause attacker-influenced method names to be inserted into a dynamically constructed eval expression.

If an application allows an attacker to control dynamic method names and invokes AwesomeMethodArray#grep with a block, the host Ruby process may execute unintended Ruby code.

Affected context

The vulnerability occurs in the AwesomeMethodArray#grep implementation when the method is called with a block and constructs Ruby source dynamically. It becomes risky when an application or surrounding integration allows untrusted input to influence method names that reach this code path.

Exploit preconditions

  • Attack surface: Application functionality that uses amazing_print method inspection or filtering
  • Required access: Ability to influence a dynamic method name or equivalent method metadata
  • Trigger point: A call to AwesomeMethodArray#grep with a block
  • Why exploitation is possible: A specially named method can be incorporated into an eval string without sufficient separation between data and executable Ruby code

Why this happens

The underlying issue is dynamic construction and evaluation of Ruby source using attacker-influenced method-name data. Interpolation syntax within that data can alter the generated expression and cause unintended code execution when the expression is evaluated. This behavior maps to CWE-94: Improper Control of Generation of Code, because untrusted data can affect executable code generation.

Potential impact

  • Arbitrary Ruby code execution in the host process
  • Exposure or modification of application data accessible to that process
  • Changes to application behavior or runtime state
  • Credential or secret access permitted by the process identity
  • Possible lateral movement through available network or system privileges

General mitigation guidance

Mitigation generally focuses on removing dynamic evaluation from paths that process attacker-influenced names.

Common defensive patterns include:

  • Replacing eval-based logic with direct Ruby APIs and structured comparisons
  • Treating method names and reflection metadata as untrusted input
  • Enforcing strict allowlists for names that can reach dynamic inspection features
  • Separating data from executable code rather than interpolating values into source strings
  • Running the application with least-privilege filesystem, network, and operating-system permissions
  • Restricting access to debugging, introspection, and formatting functionality in exposed application paths

How teams detect issues like this

Organizations can look for this class of issue through:

  • Static analysis rules that flag eval and related dynamic execution APIs
  • Searches for string interpolation or concatenation used to construct Ruby expressions
  • Code review checks for reflection APIs receiving request, file, or metadata-derived names
  • Tests using unusual but harmless method-name characters to verify that values remain data
  • Dependency and policy scanning for packages that generate executable source from external input

Automated code review and application security tools can help identify dynamic code-generation patterns, but findings should be validated against actual data flows.

Sources

SourceLink
gist.github.comgist.github.com/Zykis1024/21b13ddabf1a7d9707fd573518cefa71
github.comgithub.com/amazing-print/amazing_print
github.comgithub.com/amazing-print/amazing_print/blob/dc890dfafdf07088ea901df53c19c2710e5c5234/lib/amazing_print/core_ext/awesome_method_array.rb#L71

Frequently asked

questions

It can be exploitable through an application interface if that interface allows remote users to influence method names that reach the vulnerable grep path. The package alone does not necessarily provide a direct network attack surface.

An attacker needs a reachable data flow that controls dynamic method names or equivalent metadata, together with execution of AwesomeMethodArray#grep using a block.

The safest pattern is to remove dynamic evaluation and use non-evaluating APIs for filtering, comparison, and method inspection. Strictly constrain any names accepted by exposed functionality.

Treat reflective names as untrusted input, prohibit unnecessary dynamic execution in code policy, review generated-source patterns, and run applications with minimal privileges.

Find out what's already
exploitable in your codebase.