CVE-2021-21289
JSON

7.4high

Command Injection Vulnerability in Mechanize

Severity
7.4high CVSS:3.1 by GitHub_M
Exploit likelihood
3.55% (higher than 89% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-qrqm-fpv6-6r8g

Description

Mechanize is an open-source ruby library that makes automated web interaction easy. In Mechanize from version 2.0.0 and before version 2.7.7 there is a command injection vulnerability. Affected versions of mechanize allow 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, Mechanize::CookieJar#save_as, Mechanize#download, Mechanize::Download#save, Mechanize::File#save, and Mechanize::FileResponse#read_body. This is fixed in version 2.7.7.

Affected

Product or packageVersionsReported by
sparklemotion mechanize>= 2.0, < 2.7.7CVE List
mechanize (RubyGems)from 2.0.0 before 2.7.7GitHub Advisory Database
mechanize_project mechanizefrom 2.0 before 2.7.7NVD
fedoraproject fedora32, 33NVD
debian debian_linux9.0NVD

All scores

GitHub_M7.4high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N
GitHub7.4high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N
NVD8.3high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H
NVD7.6high CVSS:2.0AV:N/AC:H/Au:N/C:C/I:C/A:C

Classification

What each source says

CVE List

Mechanize is an open-source ruby library that makes automated web interaction easy. In Mechanize from version 2.0.0 and before version 2.7.7 there is a command injection vulnerability. Affected versions of mechanize allow 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, Mechanize::CookieJar#save_as, Mechanize#download, Mechanize::Download#save, Mechanize::File#save, and Mechanize::FileResponse#read_body. This is fixed in version 2.7.7.

GitHub Advisory Database

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.

NVD (es)

Mechanize es una biblioteca de ruby ??de código abierto que facilita la interacción web automatizada.&#xa0;En Mechanize desde versión 2.0.0 y versiones anteriores a 2.7.7, se presenta una vulnerabilidad de inyección de comandos.&#xa0;Las versiones afectadas de mechanize permiten a unos comandos del Sistema Operativo ser inyectados usando métodos de varias clases que implícitamente usan el método Kernel.open de Ruby.&#xa0;Una explotación es posible solo si es usada una entrada que no sea confiable como nombre de archivo local y sea pasada a cualquiera de estas llamadas: Mechanize::CookieJar#load, Mechanize::CookieJar#save_as, Mechanize#download, Mechanize::Download#save, Mechanize::File#save y Mechanize::FileResponse#read_body.&#xa0;Esto es corregido en versión 2.7.7

References

https://github.com/sparklemotion/mechanize/security/advisories/GHSA-qrqm-fpv6-6r8gthird-party-advisory, web
https://rubygems.org/gems/mechanize/product, third-party-advisory
https://github.com/sparklemotion/mechanize/releases/tag/v2.7.7release-notes, third-party-advisory, web
https://github.com/sparklemotion/mechanize/commit/66a6a1bfa653a5f13274a396a5e5441238656aa0patch, third-party-advisory, web
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/LBVVJUL4P4KCJH4IQTHFZ4ATXY7XXZPV/vendor-advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/YNFZ7ROYS6V4J5L5PRAJUG2AWC7VXR2V/vendor-advisory
https://lists.debian.org/debian-lts-announce/2021/02/msg00021.htmlmailing-list, third-party-advisory, web
https://security.gentoo.org/glsa/202107-17third-party-advisory, vendor-advisory, web
https://nvd.nist.gov/vuln/detail/CVE-2021-21289advisory
https://github.com/rubysec/ruby-advisory-db/blob/master/gems/mechanize/CVE-2021-21289.ymlweb
https://github.com/sparklemotion/mechanizepackage
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/LBVVJUL4P4KCJH4IQTHFZ4ATXY7XXZPVweb

Sources

SourceRecordLicence
CVE ListCVE-2021-21289 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-qrqm-fpv6-6r8g changed 2026-09-10CC-BY-4.0
NVDCVE-2021-21289 changed 2026-06-17Public domain