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

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

- **Severity:** High 8.1 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 24 Apr 2026
- **Updated:** 24 Aug 2026
- **Also known as:** ALPINE-CVE-2026-41316, ALSA-2026:18030, ALSA-2026:18039, ALSA-2026:18065, ALSA-2026:20614, BELL-CVE-2026-41316, CLEANSTART-2026-EK77943, CLEANSTART-2026-PT72236, CLSA-2026-1779745996, CLSA-2026-1781100836, DEBIAN-CVE-2026-41316, ECHO-f356-2b11-6f16, GHSA-q339-8rmv-2mhv, MINI-28qx-8vr9-x9rm, MINI-2rm4-mr5r-9hh7, MINI-48x5-jcf5-w28w, MINI-6w9c-jh5r-65w5, MINI-7fcp-qrvm-4vh8, MINI-83qg-295f-cwp3, MINI-97r8-38m9-8fw4, MINI-fmfc-gfx6-hqj5, MINI-gvgx-65f9-5cx8, MINI-hpmj-chv8-whv3, MINI-jp3g-7hqx-x2v7, MINI-jvg7-3m89-29j4, MINI-mm5r-5g65-3wcq, MINI-ppwx-vr2x-r5wc, MINI-q5c6-f36g-q9gc, MINI-q7fx-f8qm-3hf5, MINI-w2q9-cg3x-787c, MINI-w7cp-335r-r22m, OESA-2026-2263, RHSA-2026:18030, RHSA-2026:18039, RHSA-2026:18065, RHSA-2026:20614, RHSA-2026:20670, RHSA-2026:26312, RHSA-2026:26655, RHSA-2026:33478, RLSA-2026:18030, RLSA-2026:18039, RLSA-2026:18065, RLSA-2026:20614, ROOT-APP-RUBY-CVE-2026-41316, SUSE-SU-2026:3556-1, UBUNTU-CVE-2026-41316, openSUSE-SU-2026:10609-1

## 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 (Deserialization of Untrusted Data), CWE-693 (Protection Mechanism Failure)

## Which versions are affected by CVE-2026-41316?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `erb` | RubyGems | All versions | 4.0.3.1 |
| `erb` | RubyGems | All versions | 4.0.3.1 |
| `erb` | RubyGems | From 4.0.4 | 4.0.4.1 |
| `erb` | RubyGems | From 4.0.4 | 4.0.4.1 |
| `erb` | RubyGems | From 5.0.0 | 6.0.1.1 |
| `erb` | RubyGems | From 5.0.0 | 6.0.1.1 |
| `erb` | RubyGems | From 6.0.2 | 6.0.4 |
| `erb` | RubyGems | From 6.0.2 | 6.0.4 |
| `ruby-default-gems` | AlmaLinux:10 | All versions | 3.3.10-12.el10_1 |
| `ruby-doc` | AlmaLinux:10 | All versions | 3.3.10-12.el10_1 |
| `rubygem-bundler` | AlmaLinux:10 | All versions | 2.5.22-12.el10_1 |
| `rubygem-irb` | AlmaLinux:10 | All versions | 1.13.1-12.el10_1 |
| `rubygem-minitest` | AlmaLinux:10 | All versions | 5.20.0-12.el10_1 |
| `rubygem-power_assert` | AlmaLinux:10 | All versions | 2.0.3-12.el10_1 |
| `rubygem-rake` | AlmaLinux:10 | All versions | 13.1.0-12.el10_1 |
| `rubygem-rdoc` | AlmaLinux:10 | All versions | 6.6.3.1-12.el10_1 |
| `rubygem-rexml` | AlmaLinux:10 | All versions | 3.4.4-12.el10_1 |
| `rubygem-rss` | AlmaLinux:10 | All versions | 0.3.1-12.el10_1 |
| `rubygem-test-unit` | AlmaLinux:10 | All versions | 3.6.1-12.el10_1 |
| `rubygem-typeprof` | AlmaLinux:10 | All versions | 0.21.9-12.el10_1 |
| `rubygems` | AlmaLinux:10 | All versions | 3.5.22-12.el10_1 |
| `rubygems-devel` | AlmaLinux:10 | All versions | 3.5.22-12.el10_1 |
| `ruby` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `ruby-bundled-gems` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `ruby-default-gems` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `ruby-devel` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `ruby-doc` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `ruby-libs` | AlmaLinux:8 | All versions | 3.3.10-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-abrt` | AlmaLinux:8 | All versions | 0.4.0-1.module_el8.10.0+3799+191214cc |
| `rubygem-abrt-doc` | AlmaLinux:8 | All versions | 0.4.0-1.module_el8.10.0+3799+191214cc |
| `rubygem-bigdecimal` | AlmaLinux:8 | All versions | 3.1.5-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-bundler` | AlmaLinux:8 | All versions | 2.5.22-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-io-console` | AlmaLinux:8 | All versions | 0.7.1-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-irb` | AlmaLinux:8 | All versions | 1.13.1-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-json` | AlmaLinux:8 | All versions | 2.7.2-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-minitest` | AlmaLinux:8 | All versions | 5.20.0-6.module_el8.10.0+4183+69a3c42f |
| `rubygem-mysql2` | AlmaLinux:8 | All versions | 0.5.5-1.module_el8.10.0+3799+191214cc |
| `rubygem-mysql2-doc` | AlmaLinux:8 | All versions | 0.5.5-1.module_el8.10.0+3799+191214cc |
| `rubygem-pg` | AlmaLinux:8 | All versions | 1.5.4-1.module_el8.10.0+3799+191214cc |
| `rubygem-pg-doc` | AlmaLinux:8 | All versions | 1.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.

## Is CVE-2026-41316 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-41316 and fix it if it is affected.

What it is: 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.
Exploitation: There is no known exploitation of CVE-2026-41316 in the wild and no public exploit code.

Affected packages and fixed versions:
- erb (RubyGems): affected all versions; fixed in 4.0.3.1
- erb (RubyGems): affected all versions; fixed in 4.0.3.1
- erb (RubyGems): affected from 4.0.4; fixed in 4.0.4.1
- erb (RubyGems): affected from 4.0.4; fixed in 4.0.4.1
- erb (RubyGems): affected from 5.0.0; fixed in 6.0.1.1
- erb (RubyGems): affected from 5.0.0; fixed in 6.0.1.1
- erb (RubyGems): affected from 6.0.2; fixed in 6.0.4
- erb (RubyGems): affected from 6.0.2; fixed in 6.0.4

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-41316/ (Markdown: https://insights.sbomify.com/CVE-2026-41316/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-41316
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-41316
- OSV: https://osv.dev/vulnerability/CVE-2026-41316

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-41316/
Summaries are generated and may contain mistakes; the official description above is the record.
