Cyber Posture

CVE-2026-41316

High

Published: 24 April 2026

Published
24 April 2026
Modified
29 April 2026
KEV Added
Patch
CVSS Score 8.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
EPSS Score 0.0011 28.8th percentile
Risk Priority 16 60% EPSS · 20% KEV · 20% CVSS

Description

ERB is a templating system for Ruby. Ruby 2.7.0 (before ERB 2.2.0 was published on rubygems.org) introduced an `@_init` instance variable guard in `ERB#result` and `ERB#run` to prevent code execution when an ERB object is reconstructed via `Marshal.load` (deserialization). However,…

more

three other public methods that also evaluate `@src` via `eval()` were not given the same guard: `ERB#def_method`, `ERB#def_module`, and `ERB#def_class`. An attacker who can trigger `Marshal.load` on untrusted data in a Ruby application that has `erb` loaded can use `ERB#def_module` (zero-arg, default parameters) as a code execution sink, bypassing the `@_init` protection entirely. ERB 4.0.3.1, 4.0.4.1, 6.0.1.1, and 6.0.4 patch the issue.

Mitigating Controls (NIST 800-53 r5)AI

prevent

Directly mitigates the vulnerability by requiring timely patching of affected ERB versions (4.0.3.1, 4.0.4.1, 6.0.1.1, 6.0.4) to add the @_init guard to ERB#def_method, #def_module, and #def_class.

detect

Vulnerability scanning and monitoring identifies Ruby applications with vulnerable ERB gem versions exposed to deserialization-based RCE via Marshal.load.

prevent

Validates untrusted inputs to reject or sanitize malicious serialized data before deserialization with Marshal.load, blocking the crafted ERB object reconstruction.

Security SummaryAI

CVE-2026-41316 affects the ERB templating system for Ruby, enabling remote code execution through a deserialization bypass. Ruby 2.7.0 introduced an @_init instance variable guard in ERB#result and ERB#run to block code execution when an ERB object is reconstructed via Marshal.load on untrusted data. However, three other public methods—ERB#def_method, ERB#def_module, and ERB#def_class—that also evaluate @src via eval() lack this guard. Ruby applications with the erb gem loaded, prior to ERB patches in versions 4.0.3.1, 4.0.4.1, 6.0.1.1, and 6.0.4, are vulnerable. The issue carries a CVSS v3.1 score of 8.1 (AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H) and maps to CWE-693 (Protection Mechanism Failure).

An attacker can exploit this vulnerability remotely by supplying malicious serialized data to a Ruby application that deserializes it via Marshal.load while the erb gem is loaded. By crafting the data to invoke ERB#def_module (using zero-argument default parameters) as a code execution sink, the attacker fully bypasses the @_init protection, achieving arbitrary code execution. Exploitation requires network access but demands high attack complexity, with no need for privileges or user interaction.

The official advisory on GitHub (https://github.com/ruby/erb/security/advisories/GHSA-q339-8rmv-2mhv) documents the vulnerability and recommends upgrading to patched ERB versions 4.0.3.1, 4.0.4.1, 6.0.1.1, or 6.0.4 to mitigate the issue by adding the @_init guard to the affected methods.

Details

CWE(s)

MITRE ATT&CK Enterprise TechniquesAI

T1190 Exploit Public-Facing Application Initial Access
Adversaries may attempt to exploit a weakness in an Internet-facing host or system to initially access a network.
Why these techniques?

The vulnerability enables remote code execution via crafted serialized data deserialized by Marshal.load in Ruby applications using the ERB gem, directly facilitating exploitation of public-facing applications.

Confidence: HIGH · MITRE ATT&CK Enterprise v19.0

References