Skip to main content
Vulnerability Database/CVE-2026-107715

CVE-2026-107715: Mechanize Library Credential Leak Vulnerability

CVE-2026-107715 is an information disclosure flaw in Mechanize library that leaks credentials to redirect targets. Attackers can capture bearer tokens and cookies sent via request headers. This article covers technical details, affected versions, impact, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-107715 Overview

CVE-2026-107715 is an information disclosure vulnerability in the Mechanize Ruby library, used to automate interaction with websites. Versions prior to 2.14.1 forward caller-supplied credential headers to a different host after an HTTP redirect. The flaw stems from Mechanize#request_headers= being reapplied by Mechanize::HTTP::Agent#request_add_headers even after Mechanize::HTTP::Agent#response_redirect strips per-request headers. The protected header lists also omit Proxy-Authorization and Cookie2. An attacker who controls a redirect target can capture bearer tokens or session cookies supplied through request_headers= or the per-request headers argument. This issue is tracked under [CWE-200] and fixed in version 2.14.1.

Critical Impact

An attacker-controlled redirect endpoint can harvest Authorization bearer tokens, Proxy-Authorization credentials, and Cookie/Cookie2 session identifiers sent via Mechanize's request headers API.

Affected Products

  • Mechanize Ruby library versions prior to 2.14.1
  • Applications using Mechanize#request_headers= for credential delivery
  • Applications passing credential headers via the per-request headers argument to fetch

Discovery Timeline

  • 2026-10-08 - CVE-2026-107715 published to NVD
  • 2026-10-09 - Last updated in NVD database

Technical Details for CVE-2026-107715

Vulnerability Analysis

Mechanize's HTTP agent is designed to strip sensitive headers when a response redirects the client across hosts. The protection, however, is incomplete in two ways. First, the stripping logic in response_redirect removes per-request headers from the outgoing request, but request_add_headers subsequently re-merges @request_headers into the follow-up request. Any credential supplied through Mechanize#request_headers= is therefore reattached and transmitted to the redirect target.

Second, the constants CREDENTIAL_HEADERS and COOKIE_HEADERS enumerate only Authorization and Cookie. Proxy-Authorization and Cookie2 headers are never classified as sensitive and are forwarded unconditionally. Note that Mechanize#cookie_jar and Mechanize::HTTP::AuthStore are not affected, since they apply credentials based on the resolved origin rather than carrying raw headers through redirects.

Root Cause

The root cause is a design flaw in Mechanize's redirect handling pipeline. The agent treats @request_headers as agent-wide defaults re-applied on every hop of an operation, rather than caller intent scoped to the original request. Combined with an incomplete sensitive-header allowlist, this permits silent cross-origin credential leakage.

Attack Vector

An attacker who controls or compromises a redirect destination reachable from a Mechanize-driven client can observe the credentials in request headers. The attacker needs no authentication and no user interaction, but the attack requires the victim client to follow a redirect to an attacker-controlled host.

ruby
# Patch 1: Scope request_headers to the initial request only.
# Source: https://github.com/sparklemotion/mechanize/commit/02a1235842d6eda8d4a5a3d8f13aba2cecf52e4f
  #
  # +redirects+ tracks the number of redirects experienced when retrieving the
  # page.  If it is over the redirection_limit an error will be raised.
+  #
+  # +apply_request_headers+ merges #request_headers into +headers+.  It is true
+  # for a request the caller initiated and false for one continuing an
+  # operation already under way, such as following a redirect, where +headers+
+  # already carries the merged set minus anything withheld along the way.

  def fetch uri, method = :get, headers = {}, params = [],
-            referer = current_page, redirects = 0, crossed_origin = false
+            referer = current_page, redirects = 0, apply_request_headers = true
+
+    # Fold the agent defaults into the caller's headers once, at the start of
+    # the operation, so that from here on a single hash carries every header
+    # and #response_redirect can drop a credential from it for good.
+    headers = @request_headers.merge headers if apply_request_headers
ruby
# Patch 2: Expand sensitive header lists to cover Proxy-Authorization and Cookie2.
# Source: https://github.com/sparklemotion/mechanize/commit/ac49abf2869297d83c3b11bbfb8b18e63b588c95
class Mechanize::HTTP::Agent

-  CREDENTIAL_HEADERS = ['Authorization']
-  COOKIE_HEADERS = ['Cookie']
+  CREDENTIAL_HEADERS = ['Authorization', 'Proxy-Authorization']
+  COOKIE_HEADERS = ['Cookie', 'Cookie2']
  POST_HEADERS = ['Content-Length', 'Content-MD5', 'Content-Type']

Detection Methods for CVE-2026-107715

Indicators of Compromise

  • Outbound HTTP requests from Ruby applications carrying Authorization, Proxy-Authorization, Cookie, or Cookie2 headers to hosts outside the application's declared integration allowlist.
  • Gemfile.lock entries pinning mechanize at versions below 2.14.1.
  • Repeated 3xx redirect chains from trusted API endpoints to unexpected external domains in application HTTP logs.

Detection Strategies

  • Inventory Ruby application dependencies with bundle list or SBOM tooling and flag Mechanize versions earlier than 2.14.1.
  • Instrument Mechanize-based clients to log the final request URL and header names (not values) for every hop in a redirect chain.
  • Review proxy and egress logs for Mechanize User-Agent strings sending Authorization headers to hosts other than the originally invoked API.

Monitoring Recommendations

  • Alert on 3xx responses from internal API gateways that redirect to external domains, especially when a bearer token was present on the originating request.
  • Monitor newly observed external domains receiving traffic from automation hosts running Ruby workloads.
  • Correlate credential-rotation events with historical outbound traffic to detect prior exposure of tokens leaked via redirect.

How to Mitigate CVE-2026-107715

Immediate Actions Required

  • Upgrade the mechanize gem to version 2.14.1 or later across all applications and CI pipelines.
  • Rotate any bearer tokens, session cookies, or proxy credentials that were supplied via Mechanize#request_headers= or the per-request headers argument.
  • Audit application code for calls that set Authorization, Proxy-Authorization, Cookie, or Cookie2 headers through Mechanize and migrate to Mechanize::HTTP::AuthStore or cookie_jar where appropriate.

Patch Information

The fix ships in Mechanize 2.14.1. See the GitHub Security Advisory GHSA-2mwr-xjcg-37j7 and the GitHub Release v2.14.1 notes. The remediation combines three commits: scoping @request_headers application to the initial request (commit 02a12358), preventing cross-site redirect propagation (commit 94e09028), and extending the sensitive-header lists (commit ac49abf2).

Workarounds

  • Supply credentials through Mechanize::HTTP::AuthStore or Mechanize#cookie_jar instead of raw request headers, since these mechanisms are unaffected.
  • Disable automatic redirect following by setting agent.redirect_ok = false and handle 3xx responses manually, inspecting the Location header before reissuing credentialed requests.
  • Restrict Mechanize-driven workloads to egress proxies that enforce domain allowlists for authenticated API destinations.
bash
# Pin Mechanize to the patched release and refresh the lockfile
bundle update mechanize --conservative
grep 'mechanize' Gemfile.lock   # verify version >= 2.14.1

# Optional: enforce manual redirect handling for Mechanize clients
# agent = Mechanize.new
# agent.redirect_ok = false

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.