CVE-2021-41816: Cgi Buffer Overrun Vulnerability
CRITICALCVE-2021-41816 is a CRITICAL (CVSS 9.8) buffer overrun vulnerability (CWE-190: Integer Overflow or Wraparound) affecting Cgi libraries in the RubyGems ecosystem. The issue involves buffer overrun in cgi.escape_html. Remediation is available by upgrading affected packages to version 0.3.1, 0.2.1, 0.1.0.1.
CVE-2021-41816 at a Glance
Security Impact
CVSS: 9.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2021-41816
To remediate this vulnerability, upgrade all affected Cgi dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade cgi to 0.3.1
Upgrade cgi to 0.2.1
Upgrade cgi to 0.1.0.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for cgi
How to Check if You Are Affected
To determine whether your application is affected by CVE-2021-41816, inspect your project dependencies for Cgi:
inspect dependencies for cgi
Analyze the terminal output to locate any version of Cgi in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.3.1), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-190: Integer Overflow or Wraparound, where the product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. this occurs when an integer value is incremented to a value that is too large to store in the associated representation. when this occurs, the value may become a very small or negative number. In Cgi, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-41816 Affected Cgi Versions
3 component(s)References
Frequently Asked Questions
What is CVE-2021-41816?
Which Cgi versions are affected?
What version fixes CVE-2021-41816?
Is cgi affected?
What is the CVSS score of CVE-2021-41816?
What CWE is associated with CVE-2021-41816?
How can I check RubyGems dependencies for CVE-2021-41816?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-5cqm-crxm-6qpv",
"modified" : "2022-07-29T14:18:05Z",
"published" : "2021-12-14T21:36:20Z",
"aliases" : [ "CVE-2021-41816" ],
"summary" : "Buffer overrun in CGI.escape_html",
"details" : "A buffer overrun vulnerability was discovered in CGI.escape_html. This can lead to a buffer overflow when a user passes a very large string (> 700 MB) to CGI.escape_html on a platform where long type takes 4 bytes, typically, Windows.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "RubyGems",
"name" : "cgi"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.3.0"
}, {
"fixed" : "0.3.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "RubyGems",
"name" : "cgi"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.2.0"
}, {
"fixed" : "0.2.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "RubyGems",
"name" : "cgi"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.1.0.1"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-41816"
}, {
"type" : "WEB",
"url" : "https://github.com/ruby/cgi/commit/959ccf0b6a672bcc64aeaa60c6e1f9e728f1e87f"
}, {
"type" : "WEB",
"url" : "https://github.com/ruby/cgi/commit/ad079c1cb5f58eba1ffac46da79995fcf94a3a6e"
}, {
"type" : "WEB",
"url" : "https://github.com/ruby/cgi/commit/c6a37a671b556eb06140ea89cc465136b24207a6"
}, {
"type" : "WEB",
"url" : "https://github.com/ruby/cgi/commit/c728632c1c09d46cfd4ecbff9caaa3651dd1002a"
}, {
"type" : "WEB",
"url" : "https://hackerone.com/reports/1328463"
}, {
"type" : "WEB",
"url" : "https://www.ruby-lang.org/en/news/2021/11/24/buffer-overrun-in-cgi-escape_html-cve-2021-41816"
}, {
"type" : "WEB",
"url" : "https://security.netapp.com/advisory/ntap-20220303-0006"
}, {
"type" : "WEB",
"url" : "https://security.gentoo.org/glsa/202401-27"
}, {
"type" : "WEB",
"url" : "https://security-tracker.debian.org/tracker/CVE-2021-41816"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN"
}, {
"type" : "WEB",
"url" : "https://groups.google.com/g/ruby-security-ann/c/4MQ568ZG47c"
}, {
"type" : "WEB",
"url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/cgi/CVE-2021-41816.yml"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/ruby/cgi"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-190" ],
"severity" : "CRITICAL",
"github_reviewed" : true,
"github_reviewed_at" : "2021-12-14T21:34:08Z",
"nvd_published_at" : "2022-02-06T21:15:00Z"
}
}