Skip to main content

CVE-2021-21289 — Command Injection Vulnerability in mechanize

HIGH

Command Injection Vulnerability in Mechanize

Published February 2, 2021Updated September 10, 2026Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (3.55%). Schedule for your next planned update.

Does your project use an affected mechanize version?

Paste your Gemfile.lock to check it for CVE-2021-21289 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my Gemfile.lock

Summary

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.

Advisory Timeline

  • First published February 2, 2021 (2123 days ago).
  • Last revised September 10, 2026 — 2045 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Bundler
Update mechanize to 2.7.7 or later
gem install mechanize -v 2.7.7

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: RubyGems (1).

PackageFixed In
mechanize RubyGems · Affected: 2.0, 2.0.1, 2.1, 2.1.1 (+15 more)2.7.7

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

  • CWE-78
    OS Command InjectionMITRE

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 7.4 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
Required
Scope
Changed
Confidentiality
None
Integrity
High
Availability
None

CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N

Frequently Asked Questions

What is CVE-2021-21289?
Command Injection Vulnerability in Mechanize. This vulnerability has been assigned a severity rating of HIGH (CVSS score: 7.4/10).
How do I check if my project is affected by CVE-2021-21289?
CVE-2021-21289 affects mechanize. It has a 3.5% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2021-21289 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
7.4

Significant impact if exploited, or exploitable with modest effort.

EPSS Score (30-day exploit probability)
3.55%
EPSS percentile: 90.1

This places it in the top 10% of EPSS-scored vulnerabilities — 90.1% of tracked vulnerabilities score at or below it, so it is substantially more likely to be exploited than most tracked vulnerabilities.

Also Known As

GHSA-qrqm-fpv6-6r8g

Related CVEs

  • CVE-2026-126366
    HIGH

    msgpack-ruby JRuby decoder makes uncapped header-count allocations; a 5-byte message forces multi-GiB OOM

  • CVE-2026-126081
    HIGH

    Action Pack: Possible Strong Parameters Bypass in Parameters#each_key

  • CVE-2026-107715
    MEDIUM

    Mechanize sends credential headers to another host after an HTTP redirect

  • CVE-2022-31033
    MEDIUM

    Mechanize before v2.8.5 vulnerable to authorization header leak on port redirect

  • CVE-2026-107399
    MEDIUM

    Mechanize sends credential headers to another origin after a meta refresh

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my Gemfile.lock