Cloudflare WAF 防御 ruby2shell

2026 年 11 月 19 日,Ruby 团队披露了 ruby2shell(CVE-2026-132825),这是 Ruby 在进行字符串大小写转换时出现的堆缓冲区溢出漏洞。Ruby 将该漏洞评定为严重(Critical),并表示已知悉在某些场景下可实现远程代码执行的验证性利用代码。修复版本已在 Ruby 3.3.14、3.4.13 和 4.0.10 中发布。
影响范围很广。Veria Labs 报告称,Ruby on Rails 以及经典风格的 Sinatra 应用在默认配置下、在任何身份认证之前就会触发该漏洞。捆绑 Ruby 的自托管产品,包括 GitLab、GitHub Enterprise Server、Mastodon、OpenProject、Discourse 和 Chatwoot,在披露时其最新版本中搭载的都是受影响的 Ruby。
Cloudflare WAF 为所有客户拦截 ruby2shell,包括免费套餐用户。我们已在 Cloudflare Free Managed Ruleset 和 Cloudflare Managed Ruleset 中各添加了两条规则,默认动作为 Block:一条针对 ruby2shell,另一条针对 GHSA-87fm-7w84-j2px——这是 Ruby 字符串大小写转换中一个相关的整数溢出漏洞,已在同一批版本中修复。
WAF 是一种补偿性控制措施,不能替代打补丁。攻击者可能通过 WAF 看不到的路径触发该漏洞,唯一彻底的修复方式是升级 Ruby。我们的团队会持续监控攻击流量,并将在出现新攻击手法时更新规则。你可以在 WAF 变更日志中跟踪规则变动,并在 Cloudflare Zero Wire 简报中获取该漏洞的最新信息。
Cloudflare 已为自身使用 Ruby 的系统打好补丁,目前未发现任何被侵入的迹象。
Ruby 字符串带有编码信息,而除了 UTF-8 之外,Ruby 仍支持许多遗留的单字节编码,例如 ISO-8859-1(Latin-1)和 Windows-1252。在单字节编码中,每个字符占一个字节,因此改变字符串的大小写通常会产生长度相同的输出。
德语尖 S(ß)打破了这一假设。它的大写形式是两个字符:SS。在 14 种 ISO-8859 和 Windows-125x 编码中,Ruby 会写入这两个字节,但只检查了容纳一个字节的空间。据 Veria Labs 称,一个包含 21 个尖 S 字符的字符串会使输出缓冲区溢出一个字节。触发该漏洞的方法有 upcase、swapcase、downcase(:fold) 和 casecmp?。UTF-8 字符串走的是不同的代码路径,不受影响。
一个字节的溢出看似无害。但在内存破坏漏洞利用中,只要有一个字节写到堆缓冲区末尾之外,就足以破坏相邻对象或分配器元数据。Ruby 表示已知晓可将该缺陷转化为代码执行的概念验证,Veria Labs 称将在披露约一周后发布其自己的概念验证。我们预计扫描工作很快就会随之展开。
HTML 表单只能发送 GET 和 POST 请求。为模拟 PUT、PATCH 或 DELETE,许多 Web 框架会在 POST 请求中接受一个 _method 参数。Rack——大多数 Ruby Web 框架所基于的接口——在其 MethodOverride 中间件中实现了这一点,该中间件会将 _method 的值转换为大写。Rails 默认包含该中间件,经典风格的 Sinatra 应用也会启用它。攻击者可以发送一个 multipart POST 请求,其 _method 部分声明一种遗留字符集,并包含一连串 sharp s 字符。框架会在请求仍处于路由阶段、任何应用代码或身份验证检查运行之前,就对该值执行大写转换。
Veria Labs 报告称,其他框架和纯 Rack 应用默认不受影响。如果应用代码会对以遗留编码接收的字符串更改大小写,则无论该字符串来自何处,仍可能受到影响。
Ruby 版本
Ruby 3.3.13 及更早版本、3.4.0 至 3.4.12,以及 4.0.0 至 4.0.9。Veria Labs 报告称该漏洞自 Ruby 2.4.0 起就已存在。Ruby 3.2 及更早版本已停止维护,不会获得修复。
默认配置下的 Rails 和经典风格 Sinatra。任何其他会更改以遗留单字节编码表示、且由攻击者控制的字符串大小写的代码。
捆绑软件
截至 2026 年 11 月 19 日,Veria Labs 列出 GitLab 19.6.0、GitHub Enterprise Server 3.22.5、Mastodon 4.7.5、OpenProject 17.9.7、Discourse 2026.10.1 和 Chatwoot 4.20.0 在其最新版本中捆绑了受影响的 Ruby。Discourse 于 11 月 19 日将其 Docker 基础镜像迁移到 Ruby 4.0.10,因此重新构建 Docker 安装即可获得修复。
发行版软件包可以在不更改 Ruby 版本号的情况下向后移植修复,因此请对照你的发行版安全公告核对完整的软件包版本。
Ruby 3.3.14、3.4.13 和 4.0.10 还修复了另外六个内存安全漏洞,Ruby 表示其中若干漏洞可能导致代码执行。其中一个漏洞 GHSA-87fm-7w84-j2px 是同一段字符串大小写转换代码中的整数溢出,我们的第二条 WAF 规则可覆盖它。另外五个位于 Ruby 的正则表达式引擎中。它们大多要求应用编译或匹配由攻击者提供的正则表达式模式。这在 Web 应用中并不常见,但在搜索功能、过滤规则和管理工具中确实会发生。
升级每一个 Ruby 运行时都需要时间,尤其是当 Ruby 打包在自托管产品和容器镜像中时。Cloudflare WAF 可在你打补丁期间降低你的暴露风险。
这两条规则都属于 Cloudflare Free Managed Ruleset 和 Cloudflare Managed Ruleset(规则集 ID efb7b8c949ac4650a09736fc376e9aee),默认操作为 Block。
规则描述
默认操作
Ruby - 堆溢出 - CVE:CVE-2026-132825
7328f23691e44b07892ebd25b19210f1
Cloudflare Free Managed Ruleset(免费计划)
Ruby - 堆溢出 - CVE:CVE-2026-132825
1afa543a1ed84893b01df04c34402c88
Cloudflare 托管规则集(Pro、Business 和 Enterprise 套餐)
Ruby - 整数溢出 - GHSA-87fm-7w84-j2px
8660e37e86444f9f9267ba22e9855f05
Cloudflare 免费托管规则集(Free 套餐)
Ruby - 整数溢出 - GHSA-87fm-7w84-j2px
6defac6a52334542adf4a162daf25922
Cloudflare 托管规则集(Pro、Business 和 Enterprise 套餐)
在 Free 套餐中,Cloudflare Free 托管规则集会自动运行,因此无需手动开启。在付费套餐中,只要部署了 Cloudflare 托管规则集,规则就会生效。由于付费套餐让用户对规则集的部署方式拥有更多控制权,Cloudflare 托管规则集未必会在每个 zone 上处于启用状态。我们建议检查其状态,确认它正在运行。你可以使用 Zero Wire 简报中的链接,直接跳转到仪表盘中的相应规则。
当恶意输入随经过 Cloudflare 的 HTTP 请求到达时,WAF 可以拦截该漏洞利用。但它无法阻断通往存在漏洞的代码的所有路径:
内存破坏通常只是第一步。要执行命令,攻击者仍需投递第二阶段载荷,例如 shell 命令或反向 shell,然后与被攻陷的服务器进行交互。WAF 攻击评分使用机器学习为每个请求的远程代码执行载荷打分,这有助于捕获基于签名的规则可能遗漏的漏洞利用变体以及攻击后流量。在 Enterprise 套餐上创建自定义规则,对 cf.waf.score.rce le 20 的请求进行拦截或质询;在 Business 套餐上则使用 cf.waf.score.class eq "attack"。
Cloudflare 已针对 ruby2shell 修补了其使用 Ruby 的系统。我们未发现任何遭到入侵的迹象,并将继续监控。
ruby2shell 将字符串大小写转换中一个字节的计算错误,变成了在默认配置的 Rails 和 Sinatra 应用中无需认证即可实现代码执行的路径。由于公开的概念验证预计将在几天内出现,可用于修补的时间窗口很短。以下是需要采取的措施:
我们的 WAF 分析师会随着新技术的出现持续更新防护。请关注 WAF 变更日志以获取规则更新。
译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(How Cloudflare WAF protects against ruby2shell (CVE-2026-132825))
On November 19, 2026, the Ruby team disclosed ruby2shell (CVE-2026-132825), a heap buffer overflow in the way Ruby changes the case of strings. Ruby rates the flaw Critical and says it is aware of proofs of concept that achieve remote code execution in some scenarios. Fixes shipped in Ruby 3.3.14, 3.4.13, and 4.0.10.
The reach is wide. Veria Labs reports that Ruby on Rails and classic-style Sinatra applications reach the bug in their default configuration, before any authentication. Self-hosted products that bundle Ruby, including GitLab, GitHub Enterprise Server, Mastodon, OpenProject, Discourse and Chatwoot, shipped an affected Ruby in their latest release at the time of disclosure.
Cloudflare WAF blocks ruby2shell for all customers, including those on the Free plan. We have added two rules to both the Cloudflare Free Managed Ruleset and the Cloudflare Managed Ruleset, with Block as the default action: one for ruby2shell and one for GHSA-87fm-7w84-j2px, a related integer overflow in Ruby string case conversion fixed in the same releases.
The WAF is a compensating control, not a replacement for patching. Exploits can reach the bug through paths a WAF does not see, and the only complete fix is to upgrade Ruby. Our team continues to monitor attack traffic and will update the rules as new techniques appear. You can track rule changes in the WAF changelog and get the latest on the vulnerability in the Cloudflare Zero Wire briefing.
Cloudflare has patched its own systems that use Ruby, and we have found no indication of compromise.
What we know about ruby2shell
Ruby strings carry an encoding, and Ruby still supports many legacy single-byte encodings, such as ISO-8859-1 (Latin-1) and Windows-1252, alongside UTF-8. In a single-byte encoding each character takes one byte, so changing the case of a string usually produces output of the same length.
The German sharp s (ß) breaks that assumption. Its uppercase form is two characters, SS. In 14 ISO-8859 and Windows-125x encodings, Ruby writes those two bytes but checks for room for only one. According to Veria Labs, a string with 21 sharp s characters overflows the output buffer by one byte. The methods that reach the bug are upcase, swapcase, downcase(:fold) and casecmp?. UTF-8 strings take a different code path and are not affected.
A one-byte overflow can look harmless. In a memory-corruption exploit, though, a single byte written past the end of a heap buffer can be enough to corrupt an adjacent object or allocator metadata. Ruby says it is aware of proofs of concept that turn this flaw into code execution, and Veria Labs says it will publish its own proof of concept about a week after disclosure. We expect scanning to start soon after.
Why default Rails and Sinatra apps are exposed
HTML forms can only send GET and POST requests. To simulate PUT, PATCH, or DELETE, many web frameworks accept a _method parameter in a POST request. Rack, the interface most Ruby web frameworks build on, implements this in its MethodOverride middleware, which converts the value of _method to uppercase. Rails includes this middleware by default, and classic-style Sinatra applications enable it. An attacker can send a multipart POST request whose _method part declares a legacy character set and contains a run of sharp s characters. The framework upcases the value while it is still routing the request, before any application code or authentication check runs.
Veria Labs reports that other frameworks and plain Rack applications are not exposed by default. Application code that changes the case of strings received in a legacy encoding may still be affected, wherever the string comes from.
Who is affected
Condition | Details |
Ruby version | Ruby 3.3.13 and earlier, 3.4.0 through 3.4.12, and 4.0.0 through 4.0.9. Veria Labs reports the bug has been present since Ruby 2.4.0. Ruby 3.2 and earlier have reached end of life and will not receive the fix. |
Framework | Rails and classic-style Sinatra in their default configuration. Any other code that changes the case of attacker-controlled strings in a legacy single-byte encoding. |
Bundled software | As of November 19, 2026, Veria Labs lists GitLab 19.6.0, GitHub Enterprise Server 3.22.5, Mastodon 4.7.5, OpenProject 17.9.7, Discourse 2026.10.1 and Chatwoot 4.20.0 as bundling an affected Ruby in their latest release. Discourse moved its Docker base image to Ruby 4.0.10 on November 19, so rebuilding a Docker install picks up the fix. |
Distribution packages can backport fixes without changing the Ruby version number, so check the full package version against your distribution's advisory.
Six more Ruby flaws in the same release
Ruby 3.3.14, 3.4.13, and 4.0.10 also fix six other memory safety flaws, and Ruby says several of them can lead to code execution. One, GHSA-87fm-7w84-j2px, is an integer overflow in the same string case conversion code, and our second WAF rule covers it. The other five are in Ruby's regular expression engine. Most of them require the application to compile or match a regular expression pattern supplied by the attacker. That is uncommon in web applications, but it does happen in search features, filtering rules and admin tools.
How Cloudflare WAF protects you
Upgrading every Ruby runtime takes time, especially when Ruby is bundled inside self-hosted products and container images. Cloudflare WAF reduces your exposure while you patch.
New managed rules, on for every customer
Both rules are part of the Cloudflare Free Managed Ruleset and the Cloudflare Managed Ruleset (Ruleset ID efb7b8c949ac4650a09736fc376e9aee), with Block as the default action.
Rule description | Rule ID | Ruleset | Default action |
Ruby - Heap Overflow - CVE:CVE-2026-132825 | 7328f23691e44b07892ebd25b19210f1 | Cloudflare Free Managed Ruleset (Free plan) | Block |
Ruby - Heap Overflow - CVE:CVE-2026-132825 | 1afa543a1ed84893b01df04c34402c88 | Cloudflare Managed Ruleset (Pro, Business and Enterprise plans) | Block |
Ruby - Integer Overflow - GHSA-87fm-7w84-j2px | 8660e37e86444f9f9267ba22e9855f05 | Cloudflare Free Managed Ruleset (Free plan) | Block |
Ruby - Integer Overflow - GHSA-87fm-7w84-j2px | 6defac6a52334542adf4a162daf25922 | Cloudflare Managed Ruleset (Pro, Business and Enterprise plans) | Block |
On the Free plan, the Cloudflare Free Managed Ruleset runs automatically, so there is nothing to turn on. On paid plans, the rules are active wherever the Cloudflare Managed Ruleset is deployed. Because paid plans give you more control over how rulesets are deployed, the Cloudflare Managed Ruleset may not be active on every zone. We recommend checking its status to confirm that it is running. You can use the links in the Zero Wire briefing to go straight to the rules in your dashboard.
What the WAF cannot see
A WAF can block an exploit when the malicious input arrives in an HTTP request that passes through Cloudflare. It cannot block every path to the vulnerable code:
- Traffic that bypasses Cloudflare. Requests sent directly to your origin IP address, and traffic between internal services, never reach the WAF. Configure your origin to accept traffic only from Cloudflare, for example with Cloudflare Tunnel or Authenticated Origin Pulls.
- Other entry points into the same code. Ruby code that changes the case of strings from email, file imports, message queues or background jobs can reach ruby2shell without an HTTP request.
Adding defense in depth with WAF attack score
Memory corruption is usually only the first step. To run commands, an attacker still has to deliver a second-stage payload, such as shell commands or a reverse shell, and then interact with the compromised server. WAF attack score uses machine learning to score each request for remote code execution payloads, which helps catch exploit variations and post-exploitation traffic that signature-based rules can miss. Create a custom rule that blocks or challenges requests with cf.waf.score.rce le 20 on Enterprise plans, or cf.waf.score.class eq "attack" on Business plans.
Impact on Cloudflare infrastructure
Cloudflare has patched its systems that use Ruby against ruby2shell. We have found no indication of compromise and continue to monitor.
Patch now
ruby2shell turns a one-byte miscalculation in string case conversion into a pre-authentication path to code execution in default Rails and Sinatra apps. With a public proof of concept expected within days, the window to patch is short. Here is what to do:
- Check your WAF coverage. On the Free plan, the ruby2shell rules are already blocking. On paid plans, confirm the Cloudflare Managed Ruleset is deployed and the rules have not been overridden.
- Upgrade Ruby to 3.3.14, 3.4.13 or 4.0.10 and restart every Ruby process, including background workers. Rebuild container images. Move applications on Ruby 3.2 or earlier to a supported series.
- Update self-hosted products that bundle Ruby, such as GitLab, GitHub Enterprise Server, Mastodon, OpenProject and Chatwoot, as each vendor releases a fix. Rebuild Discourse Docker installs now.
- Inventory your runtimes. The Zero Wire briefing includes a prompt you can give an AI agent to find every affected Ruby runtime in your infrastructure.
Our WAF analysts will keep updating protections as new techniques appear. Follow the WAF changelog for rule updates.
正文保留英文原文,标题与摘要由机器翻译。
原文发布于 Cloudflare Blog(How Cloudflare WAF protects against ruby2shell (CVE-2026-132825)),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。