CVE-2021-31799: Rdoc Arbitrary Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-ggxm-pgc9-g7fp
CVSS 7.0
CWE-78 CWE-74 CWE-77
Published
Advisory Summary

CVE-2021-31799 is a HIGH (CVSS 7.0) arbitrary code execution vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Rdoc libraries in the RubyGems ecosystem. The issue involves arbitrary code execution in rdoc. Remediation is available by upgrading affected packages to version 6.1.2.1, 6.2.1.1, 6.3.1.

CVE-2021-31799 at a Glance

CVE Identifier CVE-2021-31799
GHSA Identifier GHSA-ggxm-pgc9-g7fp
Severity HIGH
CVSS v3.1 Base Score 7.0
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Rdoc
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 7.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
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-31799

To remediate this vulnerability, upgrade all affected Rdoc dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

rdoc fixed: 6.1.2.1
Upgrade rdoc to 6.1.2.1
rdoc fixed: 6.2.1.1
Upgrade rdoc to 6.2.1.1
rdoc fixed: 6.3.1
Upgrade rdoc to 6.3.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 rdoc

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-31799, inspect your project dependencies for Rdoc:

inspect dependencies for rdoc

Analyze the terminal output to locate any version of Rdoc in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.1.2.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-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In Rdoc, 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

In RDoc 3.11 through 6.x before 6.3.1, as distributed with Ruby through 3.0.1, it is possible to execute arbitrary code via | and tags in a filename.

CVE-2021-31799 Affected Rdoc Versions

3 component(s)
Fixed Versions:
6.1.2.16.2.1.16.3.1
Product / Package Ecosystem Affected Versions Fixed Version
rdoc
RubyGems
≥ 3.11
< 6.1.2.1
6.1.2.1
rdoc
RubyGems
≥ 6.2.0
< 6.2.1.1
6.2.1.1
rdoc
RubyGems
≥ 6.3.0
< 6.3.1
6.3.1

References

Frequently Asked Questions

What is CVE-2021-31799?
CVE-2021-31799 is a security vulnerability in Rdoc involving Arbitrary Code Execution in Rdoc under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Rdoc versions are affected?
Affected versions include releases prior to 6.1.2.1, 6.2.1.1, 6.3.1 across affected packages: rdoc.
What version fixes CVE-2021-31799?
Upgrading to 6.1.2.1, 6.2.1.1, 6.3.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is rdoc affected?
Yes, rdoc is affected in releases prior to 6.1.2.1, 6.2.1.1, 6.3.1. Upgrade your dependency to 6.1.2.1, 6.2.1.1, 6.3.1 or later.
What is the CVSS score of CVE-2021-31799?
CVE-2021-31799 has a CVSS v3.1 base score of 7.0 (HIGH) with vector string CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-31799?
CVE-2021-31799 is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check RubyGems dependencies for CVE-2021-31799?
Run the dependency tree command: 'inspect dependencies for rdoc'. 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-ggxm-pgc9-g7fp",
  "modified" : "2024-11-14T01:01:40Z",
  "published" : "2021-09-01T18:53:15Z",
  "aliases" : [ "CVE-2021-31799" ],
  "summary" : "Arbitrary Code Execution in Rdoc",
  "details" : "In RDoc 3.11 through 6.x before 6.3.1, as distributed with Ruby through 3.0.1, it is possible to execute arbitrary code via | and tags in a filename.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "rdoc"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.11"
      }, {
        "fixed" : "6.1.2.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "rdoc"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.2.0"
      }, {
        "fixed" : "6.2.1.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "rdoc"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.3.0"
      }, {
        "fixed" : "6.3.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-31799"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/rdoc/commit/a7f5d6ab88632b3b482fe10611382ff73d14eed7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ruby/rdoc"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/rdoc/CVE-2021-31799.yml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/10/msg00009.html"
  }, {
    "type" : "WEB",
    "url" : "https://security-tracker.debian.org/tracker/CVE-2021-31799"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202401-05"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20210902-0004"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuapr2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.ruby-lang.org/en/news/2021/05/02/os-command-injection-in-rdoc"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-77", "CWE-78" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-08-02T18:08:41Z",
    "nvd_published_at" : "2021-07-30T14:15:00Z"
  }
}