ERB has an @_init deserialization guard bypass via def_module / def_method / def_class
ruby erb
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| erb RubyGems |
|
|
ruby erb
| Product | Affected | Fixed in |
|---|---|---|
| erb RubyGems |
|
|
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, 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.
From the CVE record · GitHub_M
ERB#def_module can evaluate code from a deserialized ERB object without the @_init guard. An attacker can execute code if they can cause a Ruby application with erb loaded to call Marshal.load on untrusted data.
Check Ruby applications using the RubyGems erb package at versions below 4.0.3.1, from 4.0.4 to below 4.0.4.1, from 5.0.0 to below 6.0.1.1, or from 6.0.2 to below 6.0.4.