CVE-2021-41816
Buffer overrun in CGI.escape_html
Also known as GHSA-5cqm-crxm-6qpv
Mitigation
- Upgrade cgi to one of 0.3.1, 0.2.1, 0.1.0.1 (or later in the same release line).
Who should check
- Projects that depend on RubyGems package cgi (>= 0.3.0, < 0.3.1)
- Anyone running n/a (versions: see the vendor advisory)
Vulnerability facts
- Affected
- cgi >= 0.3.0, < 0.3.1
- Fixed in
- 0.3.1, 0.2.1, 0.1.0.1
- Exploited in the wild
- Not in CISA KEV
- Public exploit / PoC
- Yes: see the exploit references below
- Remote exploitation
- Remote, no login needed
- CVSS
- 9.8 (v3.1, NVD)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:HOpen in CVSS calculator
Show all 8 CVSS metrics
- Attack vector: Network
- Attack complexity: Low
- Privileges required: None
- User interaction: None
- Scope: Unchanged
- Confidentiality impact: High
- Integrity impact: High
- Availability impact: High
- EPSS
- 4.90% chance of exploitation in 30 days (percentile 93, 2026-11-26)
- CWE
- CWE-190
- Modified
Description
CGI.escape_html in Ruby before 2.7.5 and 3.x before 3.0.3 has an integer overflow and resultant buffer overflow via a long string on platforms (such as Windows) where size_t and long have different numbers of bytes. This also affects the CGI gem before 0.3.1 for Ruby.
Affected and fixed versions
| Package / product | Affected | Fixed | Source |
|---|---|---|---|
| RubyGems cgi | >= 0.3.0, < 0.3.1 | 0.3.1, 0.2.1, 0.1.0.1 | osv |
| n/a | — | — | nvd |
Check your systems with an agent
Paste this into Claude Code, Cursor or another coding agent. It only reads; it changes nothing.
Check whether anything I run is affected by CVE-2021-41816. Work read-only: do not install, upgrade, delete or change anything. Details: https://flawdb.com/CVE-2021-41816.md Affected: cgi >= 0.3.0, < 0.3.1 Fixed in: 0.3.1, 0.2.1, 0.1.0.1 Steps: 1. Search this machine and project for cgi (RubyGems), n/a: dependency manifests and lockfiles, installed packages, container images and running services. 2. For each match, note the installed version and whether it is inside the affected range. 3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
References
Vendor advisories
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF/
- https://security.gentoo.org/glsa/202401-27
- https://nvd.nist.gov/vuln/detail/CVE-2021-41816
Patches
- https://github.com/ruby/cgi/commit/959ccf0b6a672bcc64aeaa60c6e1f9e728f1e87f
- https://github.com/ruby/cgi/commit/ad079c1cb5f58eba1ffac46da79995fcf94a3a6e
- https://github.com/ruby/cgi/commit/c6a37a671b556eb06140ea89cc465136b24207a6
- https://github.com/ruby/cgi/commit/c728632c1c09d46cfd4ecbff9caaa3651dd1002a
Exploits and PoCs
Other
- https://hackerone.com/reports/1328463
- https://security-tracker.debian.org/tracker/CVE-2021-41816
- https://security.netapp.com/advisory/ntap-20220303-0006/
- https://www.ruby-lang.org/en/news/2021/11/24/buffer-overrun-in-cgi-escape_html-cve-2021-41816
- https://security.netapp.com/advisory/ntap-20220303-0006
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN
- https://groups.google.com/g/ruby-security-ann/c/4MQ568ZG47c
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/cgi/CVE-2021-41816.yml
- https://github.com/ruby/cgi
FAQ
Is CVE-2021-41816 being exploited?
There is no confirmed exploitation: CVE-2021-41816 is not in the CISA Known Exploited Vulnerabilities catalog. Public exploit code or a proof of concept is available. EPSS estimates a 4.90% chance of exploitation in the next 30 days (as of 2026-11-26).
How serious is CVE-2021-41816?
Critical: CVSS 9.8 (v3.1, scored by NVD). Remote, no login needed.
Which versions are affected by CVE-2021-41816?
cgi >= 0.3.0, < 0.3.1.
Is there a fix for CVE-2021-41816?
Yes. Fixed in 0.3.1, 0.2.1, 0.1.0.1. Upgrade cgi to one of 0.3.1, 0.2.1, 0.1.0.1 (or later in the same release line).
How do I check if I'm affected by CVE-2021-41816?
Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.