CVE-2021-41816: Cgi Buffer Overrun Vulnerability

CRITICAL
Advisory Identifier: GHSA-5cqm-crxm-6qpv
CVSS 9.8
CWE-190
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2021-41816
GHSA Identifier GHSA-5cqm-crxm-6qpv
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-190: Integer Overflow or Wraparound
Affected Product Cgi
Package Ecosystem RubyGems
Published Date
Last Updated

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

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (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.

cgi fixed: 0.3.1
Upgrade cgi to 0.3.1
cgi fixed: 0.2.1
Upgrade cgi to 0.2.1
cgi fixed: 0.1.0.1
Upgrade cgi to 0.1.0.1
Verify Direct and Transitive Dependencies

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

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.

CVE-2021-41816 Affected Cgi Versions

3 component(s)
Fixed Versions:
0.3.10.2.10.1.0.1
Product / Package Ecosystem Affected Versions Fixed Version
cgi
RubyGems
≥ 0.3.0
< 0.3.1
0.3.1
cgi
RubyGems
≥ 0.2.0
< 0.2.1
0.2.1
cgi
RubyGems
< 0.1.0.1
0.1.0.1

References

www.ruby-lang.org/en/news/2021/11/24/... WEB
https://www.ruby-lang.org/en/news/2021/11/24/buffer-overrun-in-cgi-escape_html-cve-2021-41816
Cgi Security Information SECURITY
https://security.netapp.com/advisory/ntap-20220303-0006
Cgi Security Information SECURITY
https://security.gentoo.org/glsa/202401-27
Cgi Security Information SECURITY
https://security-tracker.debian.org/tracker/CVE-2021-41816
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTOJGS5IEFDK3UOO7IY4OTTFGHGLSWZF
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IUXQCH6FRKANCVZO2Q7D2SQX33FP3KWN
Cgi Security Information SECURITY
https://groups.google.com/g/ruby-security-ann/c/4MQ568ZG47c
Cgi Source Repository REPOSITORY
https://github.com/rubysec/ruby-advisory-db/blob/master/gems/cgi/CVE-2021-41816.yml
Cgi Source Repository REPOSITORY
https://github.com/ruby/cgi
NVD — CVE-2021-41816 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-41816
Security Fix Commit FIX COMMIT
https://github.com/ruby/cgi/commit/959ccf0b6a672bcc64aeaa60c6e1f9e728f1e87f
Security Fix Commit FIX COMMIT
https://github.com/ruby/cgi/commit/ad079c1cb5f58eba1ffac46da79995fcf94a3a6e
Security Fix Commit FIX COMMIT
https://github.com/ruby/cgi/commit/c6a37a671b556eb06140ea89cc465136b24207a6
Security Fix Commit FIX COMMIT
https://github.com/ruby/cgi/commit/c728632c1c09d46cfd4ecbff9caaa3651dd1002a
hackerone.com/reports/1328463 WEB
https://hackerone.com/reports/1328463

Frequently Asked Questions

What is CVE-2021-41816?
CVE-2021-41816 is a security vulnerability in Cgi involving Buffer overrun in CGI.escape_html under CWE-190: Integer Overflow or Wraparound.
Which Cgi versions are affected?
Affected versions include releases prior to 0.3.1, 0.2.1, 0.1.0.1 across affected packages: cgi.
What version fixes CVE-2021-41816?
Upgrading to 0.3.1, 0.2.1, 0.1.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cgi affected?
Yes, cgi is affected in releases prior to 0.3.1, 0.2.1, 0.1.0.1. Upgrade your dependency to 0.3.1, 0.2.1, 0.1.0.1 or later.
What is the CVSS score of CVE-2021-41816?
CVE-2021-41816 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-41816?
CVE-2021-41816 is classified under CWE-190: Integer Overflow or Wraparound (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.).
How can I check RubyGems dependencies for CVE-2021-41816?
Run the dependency tree command: 'inspect dependencies for cgi'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}