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

High 8.1 Published Updated

Attackers can bypass deserialization guards in the Ruby ERB library to execute arbitrary code via specific public methods.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2026-41316?

CVE-2026-41316 is a high-severity unsafe deserialization vulnerability in ruby erb, published on 24 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official 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, 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.

Weakness: CWE-502, CWE-693

Which versions are affected by CVE-2026-41316?

8 open source packages ship an affected version, including erb.

PackageAffectedFixed in
erb RubyGemsAll versions4.0.3.1
erb RubyGemsAll versions4.0.3.1
erb RubyGemsFrom 4.0.44.0.4.1
erb RubyGemsFrom 4.0.44.0.4.1
erb RubyGemsFrom 5.0.06.0.1.1
erb RubyGemsFrom 5.0.06.0.1.1
2 more packages
erb RubyGemsFrom 6.0.26.0.4
erb RubyGemsFrom 6.0.26.0.4
Linux distribution packages (32)
ruby-default-gems AlmaLinux:10All versions3.3.10-12.el10_1
ruby-doc AlmaLinux:10All versions3.3.10-12.el10_1
rubygem-bundler AlmaLinux:10All versions2.5.22-12.el10_1
rubygem-irb AlmaLinux:10All versions1.13.1-12.el10_1
rubygem-minitest AlmaLinux:10All versions5.20.0-12.el10_1
rubygem-power_assert AlmaLinux:10All versions2.0.3-12.el10_1
rubygem-rake AlmaLinux:10All versions13.1.0-12.el10_1
rubygem-rdoc AlmaLinux:10All versions6.6.3.1-12.el10_1
rubygem-rexml AlmaLinux:10All versions3.4.4-12.el10_1
rubygem-rss AlmaLinux:10All versions0.3.1-12.el10_1
rubygem-test-unit AlmaLinux:10All versions3.6.1-12.el10_1
rubygem-typeprof AlmaLinux:10All versions0.21.9-12.el10_1
rubygems AlmaLinux:10All versions3.5.22-12.el10_1
rubygems-devel AlmaLinux:10All versions3.5.22-12.el10_1
ruby AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
ruby-bundled-gems AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
ruby-default-gems AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
ruby-devel AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
ruby-doc AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
ruby-libs AlmaLinux:8All versions3.3.10-6.module_el8.10.0+4183+69a3c42f
rubygem-abrt AlmaLinux:8All versions0.4.0-1.module_el8.10.0+3799+191214cc
rubygem-abrt-doc AlmaLinux:8All versions0.4.0-1.module_el8.10.0+3799+191214cc
rubygem-bigdecimal AlmaLinux:8All versions3.1.5-6.module_el8.10.0+4183+69a3c42f
rubygem-bundler AlmaLinux:8All versions2.5.22-6.module_el8.10.0+4183+69a3c42f
rubygem-io-console AlmaLinux:8All versions0.7.1-6.module_el8.10.0+4183+69a3c42f
rubygem-irb AlmaLinux:8All versions1.13.1-6.module_el8.10.0+4183+69a3c42f
rubygem-json AlmaLinux:8All versions2.7.2-6.module_el8.10.0+4183+69a3c42f
rubygem-minitest AlmaLinux:8All versions5.20.0-6.module_el8.10.0+4183+69a3c42f
rubygem-mysql2 AlmaLinux:8All versions0.5.5-1.module_el8.10.0+3799+191214cc
rubygem-mysql2-doc AlmaLinux:8All versions0.5.5-1.module_el8.10.0+3799+191214cc
rubygem-pg AlmaLinux:8All versions1.5.4-1.module_el8.10.0+3799+191214cc
rubygem-pg-doc AlmaLinux:8All versions1.5.4-1.module_el8.10.0+3799+191214cc

How do I fix CVE-2026-41316?

Upgrade erb to a fixed version for your release line: 4.0.3.1, 4.0.4.1, 6.0.1.1 or 6.0.4.

Upgrade, and only deserialise data from trusted sources or with an allow-list of types. More about Unsafe deserialization.

Is CVE-2026-41316 being exploited?

There is no known exploitation of CVE-2026-41316 in the wild and no public exploit code.

Sources

Also known as ALPINE-CVE-2026-41316, ALSA-2026:18030, ALSA-2026:18039, ALSA-2026:18065, ALSA-2026:20614, BELL-CVE-2026-41316 and 42 more.

Is CVE-2026-41316 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free