CVE-2021-21289: Mechanize Command Injection Vulnerability Vulnerability

HIGH
Advisory Identifier: GHSA-qrqm-fpv6-6r8g
CVSS 7.4
CWE-78
Published
Advisory Summary

CVE-2021-21289 is a HIGH (CVSS 7.4) command injection vulnerability vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Mechanize libraries in the RubyGems ecosystem. The issue involves command injection vulnerability in mechanize. Remediation is available by upgrading affected packages to version 2.7.7.

CVE-2021-21289 at a Glance

CVE Identifier CVE-2021-21289
GHSA Identifier GHSA-qrqm-fpv6-6r8g
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Mechanize
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 7.4

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:R/S:C/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2021-21289

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

mechanize fixed: 2.7.7
Upgrade mechanize to 2.7.7
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 mechanize

How to Check if You Are Affected

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

inspect dependencies for mechanize

Analyze the terminal output to locate any version of Mechanize in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.7.7), 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 Mechanize, 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

This security advisory has been created for public disclosure of a Command Injection vulnerability that was responsibly reported by @kyoshidajp (Katsuhiko YOSHIDA). ### Impact Mechanize `>= v2.0`, `< v2.7.7` allows for OS commands to be injected using several classes' methods which implicitly use Ruby's `Kernel.open` method. Exploitation is possible only if untrusted input is used as a local filename and passed to any of these calls: - `Mechanize::CookieJar#load`: since v2.0 (see 208e3ed) - `Mechanize::CookieJar#save_as`: since v2.0 (see 5b776a4) - `Mechanize#download`: since v2.2 (see dc91667) - `Mechanize::Download#save` and `#save!` since v2.1 (see 98b2f51, bd62ff0) - `Mechanize::File#save` and `#save_as`: since v2.1 (see 2bf7519) - `Mechanize::FileResponse#read_body`: since v2.0 (see 01039f5) ### Patches These vulnerabilities are patched in Mechanize v2.7.7. ### Workarounds No workarounds are available. We recommend upgrading to v2.7.7 or later. ### References See https://docs.rubocop.org/rubocop/cops_security.html#securityopen for background on why `Kernel.open` should not be used with untrusted input. ### For more information If you have any questions or comments about this advisory, please open an issue in [sparklemotion/mechanize](https://github.com/sparklemotion/mechanize/issues/new).

CVE-2021-21289 Affected Mechanize Versions

1 component(s)
Fixed Versions:
2.7.7
Product / Package Ecosystem Affected Versions Fixed Version
mechanize
RubyGems
≥ 2.0.0
< 2.7.7
2.7.7

References

Frequently Asked Questions

What is CVE-2021-21289?
CVE-2021-21289 is a security vulnerability in Mechanize involving Command Injection Vulnerability in Mechanize under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Mechanize versions are affected?
Affected versions include releases prior to 2.7.7 across affected packages: mechanize.
What version fixes CVE-2021-21289?
Upgrading to 2.7.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mechanize affected?
Yes, mechanize is affected in releases prior to 2.7.7. Upgrade your dependency to 2.7.7 or later.
What is the CVSS score of CVE-2021-21289?
CVE-2021-21289 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2021-21289?
CVE-2021-21289 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-21289?
Run the dependency tree command: 'inspect dependencies for mechanize'. 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-qrqm-fpv6-6r8g",
  "modified" : "2022-04-27T20:24:21Z",
  "published" : "2021-02-02T18:50:27Z",
  "aliases" : [ "CVE-2021-21289" ],
  "summary" : "Command Injection Vulnerability in Mechanize",
  "details" : "This security advisory has been created for public disclosure of a Command Injection vulnerability that was responsibly reported by @kyoshidajp (Katsuhiko YOSHIDA).\n\n### Impact\n\nMechanize `>= v2.0`, `< v2.7.7` allows for OS commands to be injected using several classes' methods which implicitly use Ruby's `Kernel.open` method. Exploitation is possible only if untrusted input is used as a local filename and passed to any of these calls:\n\n- `Mechanize::CookieJar#load`: since v2.0 (see 208e3ed)\n- `Mechanize::CookieJar#save_as`: since v2.0 (see 5b776a4)\n- `Mechanize#download`: since v2.2 (see dc91667)\n- `Mechanize::Download#save` and `#save!` since v2.1 (see 98b2f51, bd62ff0)\n- `Mechanize::File#save` and `#save_as`: since v2.1 (see 2bf7519)\n- `Mechanize::FileResponse#read_body`: since v2.0 (see 01039f5)\n\n\n### Patches\n\nThese vulnerabilities are patched in Mechanize v2.7.7.\n\n\n### Workarounds\n\nNo workarounds are available. We recommend upgrading to v2.7.7 or later.\n\n\n### References\n\nSee https://docs.rubocop.org/rubocop/cops_security.html#securityopen for background on why `Kernel.open` should not be used with untrusted input.\n\n\n### For more information\n\nIf you have any questions or comments about this advisory, please open an issue in [sparklemotion/mechanize](https://github.com/sparklemotion/mechanize/issues/new).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "mechanize"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.7.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/mechanize/security/advisories/GHSA-qrqm-fpv6-6r8g"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21289"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/mechanize/commit/66a6a1bfa653a5f13274a396a5e5441238656aa0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/mechanize/CVE-2021-21289.yml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sparklemotion/mechanize"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/mechanize/releases/tag/v2.7.7"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/02/msg00021.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/LBVVJUL4P4KCJH4IQTHFZ4ATXY7XXZPV"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/YNFZ7ROYS6V4J5L5PRAJUG2AWC7VXR2V"
  }, {
    "type" : "WEB",
    "url" : "https://rubygems.org/gems/mechanize"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202107-17"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-78" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-02-02T18:50:15Z",
    "nvd_published_at" : "2021-02-02T19:15:00Z"
  }
}