Skip to content
Fencer Vulns
critical 9.8

CVE-2021-41816 json

Buffer overrun in CGI.escape_html

published 2021-12-14 4 y ago modified 2026-08-13 2 mo ago also GHSA-5cqm-crxm-6qpv , EUVD-2021-2447

cvss
9.8
version 3.1, NVD
cisa kev
Not listed
not in CISA's catalog
epss
4.9%
EPSS 4.9% chance of exploitation in 30 days, percentile 92%
public exploits
0
none known

Summary

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.

Patch / fix

  • rubygems cgi 0.1.0.1, 0.2.1, 0.3.1
  • ruby-lang cgi 0.3.1
  • ruby2.7 Debian 11 2.7.4-1+deb11u1

debian advisories DEBIAN-CVE-2021-41816

  • ruby2.7 Ubuntu 20.04 LTS 2.7.0-5ubuntu1.6
  • ruby3.0 Ubuntu 22.04 LTS 3.0.2-7ubuntu2

ubuntu advisories UBUNTU-CVE-2021-41816

Ubuntu security data © Canonical Ltd., from https://github.com/canonical/ubuntu-security-notices via OSV; changed: normalised to fixed package versions per release. CC BY-SA 4.0

  • rh-ruby27-ruby RHEL 3 SOFTWARE_COLLECTIONS 2.7.6-131.el7
  • rh-ruby27-rubygems RHEL 3 SOFTWARE_COLLECTIONS 3.1.6-131.el7
  • rh-ruby27-ruby-libs RHEL 3 SOFTWARE_COLLECTIONS 2.7.6-131.el7
  • rh-ruby27-rubygem-irb RHEL 3 SOFTWARE_COLLECTIONS 1.2.6-131.el7
  • rh-ruby27-rubygem-json RHEL 3 SOFTWARE_COLLECTIONS 2.3.0-131.el7
  • rh-ruby27-rubygem-racc RHEL 3 SOFTWARE_COLLECTIONS 1.4.16-131.el7
  • rh-ruby27-rubygem-rake RHEL 3 SOFTWARE_COLLECTIONS 13.0.1-131.el7
  • rh-ruby27-rubygem-rdoc RHEL 3 SOFTWARE_COLLECTIONS 6.2.1.1-131.el7

red hat advisories RHSA-2022:6856RHSA-2022:6855

  • ruby4.0 openSUSE Tumbleweed 4.0.0~preview2-1.1
  • ruby3.4 openSUSE Tumbleweed 3.4.1-1.1
  • ruby2.7 openSUSE Tumbleweed 2.7.5-1.1
  • ruby3.0 openSUSE Tumbleweed 3.0.3-1.1
  • ruby3.1 openSUSE Tumbleweed 3.1.0-1.1
  • ruby3.2 openSUSE Tumbleweed 3.2.1-1.1
  • ruby3.3 openSUSE Tumbleweed 3.3.0-1.2

opensuse advisories openSUSE-SU-2025:15819-1openSUSE-SU-2025:14621-1openSUSE-SU-2024:11657-1openSUSE-SU-2024:11658-1openSUSE-SU-2024:11786-1openSUSE-SU-2024:12712-1

  • ruby Alpine 3.14, Alpine 3.13, Alpine 3.12 2.7.5-r0
  • ruby Alpine 3.24, Alpine 3.23, Alpine 3.22 +7 more 3.0.3-r0

alpine advisories ALPINE-CVE-2021-41816

Alpine secdb © Alpine Linux, from https://secdb.alpinelinux.org via OSV; changed: normalised to fixed package versions per release. CC BY-SA 4.0

Vendor advisories

What the vendors themselves say about their products: affected, fixed or not affected, and what to do.

red hat product security vex CVE-2021-41816 updated cvss 7.5

ruby: buffer overflow in CGI.escape_html

  • Red Hat Software Collections for RHEL Workstation(v. 7) rh-ruby27-ruby 2.7.6-131.el7, rh-ruby30-ruby 3.0.4-149.el7, rh-ruby27-rubygems 3.1.6-131.el7, rh-ruby27-ruby-libs 2.7.6-131.el7, rh-ruby30-ruby-libs 3.0.4-149.el7, rh-ruby30-rubygems 3.2.33-149.el7, +31 more Red Hat Software Collections for RHEL(v. 7) rh-ruby27-ruby 2.7.6-131.el7, rh-ruby30-ruby 3.0.4-149.el7, rh-ruby27-rubygems 3.1.6-131.el7, rh-ruby27-ruby-libs 2.7.6-131.el7, rh-ruby30-ruby-libs 3.0.4-149.el7, rh-ruby30-rubygems 3.2.33-149.el7, +31 more
    fixed: vendor fix RHSA-2022:6856
  • Red Hat Enterprise Linux 6 ruby, ruby-ri, ruby-irb, ruby-libs, ruby-rdoc, ruby-tcltk Red Hat Enterprise Linux 7 ruby, ruby-irb, rubygems, ruby-libs, ruby-tcltk, rubygem-json, +6 more Red Hat Enterprise Linux 8 ruby, ruby-irb, rubygems, ruby-libs, rubygem-pg, rubygem-irb, +25 more Red Hat Enterprise Linux 9 ruby, rubygems, ruby-libs, rubygem-irb, rubygem-rbs, rubygem-rss, +13 more Red Hat Software Collections rh-ruby26-ruby, rh-ruby26-rubygems, rh-ruby26-ruby-libs, rh-ruby26-rubygem-irb, rh-ruby26-rubygem-json, rh-ruby26-rubygem-rake, +12 more
    not affected: vulnerable code not present

Red Hat CSAF VEX © Red Hat, Inc., from https://security.access.redhat.com/data/csaf/v2/vex/; changed: reduced to product statuses and remediations. CC BY 4.0 · csaf

Exploit prediction

4.90% chance of exploitation in the next 30 days, higher than 92% of all scored CVEs (FIRST EPSS, 2026-11-08).

Exploits and checks

  • ruby-lang.org https://www.ruby-lang.org/en/news/2021/11/24/buffer-overrun-in-cgi-escape_html-cve-2021-41816/ referenced PoC, tagged "exploit" by a source, unverified

CVSS scores

assigned by version score vector
NVD 3.1 9.8 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
NVD 2.0 7.5 AV:N/AC:L/Au:N/C:P/I:P/A:P
GitHub 3.1 9.8 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Affected packages

ecosystem package affected fixed in
rubygems cgi
>=0.3.0, <0.3.1
>=0.2.0, <0.2.1
<0.1.0.1
0.3.1
0.2.1
0.1.0.1

Classification

Weakness
  • CWE-190 Integer Overflow or Wraparound

References

Sources

Fencer Vulns keeps one entry per vulnerability: the CVE id wins, then GHSA, and records that alias each other are merged, except that two CVEs always keep separate entries. The same data is available as JSON.