RubySec

Providing security resources for the Ruby community

CVE-2026-41316 (erb): ERB has an @_init deserialization guard bypass via def_module / def_method / def_class

ERB has an @_init deserialization guard bypass via def_module / def_method / def_class

Published: April 13, 2026

SECURITY IDENTIFIERS

GEM

erb

SEVERITY

CVSS v3.x: 8.1 (High)

PATCHED VERSIONS

~> 4.0.3.1 ~> 4.0.4.1 ~> 6.0.1.1 >= 6.0.4

DESCRIPTION

ERB implements an @_init guard to prevent code execution when ERB objects are reconstructed via Marshal.load on untrusted data. However, ERB#def_method, ERB#def_module, and ERB#def_class evaluate the template source without checking this guard, allowing an attacker who controls the data passed to Marshal.load to bypass the protection and execute arbitrary code. In particular, def_module takes no arguments, making it straightforward to invoke as part of a deserialization gadget chain.

Please update the erb gem to version 4.0.3.1, 4.0.4.1, 6.0.1.1, 6.0.4 or later.

RELATED