CVE-2026-107715: Mechanize sends credential headers to another host after an HTTP redirect

Published Oct 8, 2026
·
Updated

Summary

mechanize leaked credentials to the redirect target when an HTTP redirect crossed to another host. Credentials set through Mechanize#requestheaders= leaked even when they were Authorization.

Details

Two defects, both in lib/mechanize/http/agent.rb.

1. Mechanize#requestheaders= bypassed the redirect strip entirely. #requestaddheaders copied @requestheaders onto every request unconditionally, with no host check, including the request issued after a redirect. The strip in #responseredirect mutated only the per-request headers hash and never touched agent state. Because requestheaders= is the documented way to set a default credential for every request, the header the code explicitly protected — Authorization — was the one most likely to leak.

2. The strip list omitted Proxy-Authorization and Cookie2. Only CREDENTIALHEADERS = ['Authorization'] and COOKIEHEADERS = ['Cookie'] were removed from the per-request headers hash on a cross-host redirect.

Cookies held in Mechanize#cookiejar and credentials held in Mechanize::HTTP::AuthStore are not affected. Both are looked up per-URI, so they never follow a redirect to a foreign host. The exposure was limited to headers the caller set by hand.

PoC

ruby agent = Mechanize.new agent.requestheaders = { 'Authorization' => 'Bearer secret' } agent.get('https://example.test/redirects-to-attacker') the request to the attacker's host carries "Authorization: Bearer secret"

Impact

An attacker who controls a redirect target — through an open redirect on the site being fetched, an attacker-supplied fetch URL, DNS rebinding, or MITM — captures bearer tokens and session cookies from any mechanize agent that sets credentials through requestheaders= or the per-request headers argument. Disclosure only; no integrity or availability impact.

Patches

Fixed in mechanize v2.14.1.

- Credentials and cookies are withheld from a request that follows a redirect across an origin, from both header sources: the per-request headers argument and Mechanize#requestheaders=. - CREDENTIALHEADERS gains Proxy-Authorization; COOKIEHEADERS gains Cookie2.

Proxy-Authorization is withheld here although curl does not withhold it, because Net::HTTP tunnels https: requests with CONNECT, so a caller-supplied Proxy-Authorization travels inside the tunnel to the origin server rather than to the proxy.

Headers set through Mechanize#requestheaders= no longer reach a redirect target on another origin when they are credentials. Callers that relied on the previous behavior will see those headers withheld.

What this fix does not cover

Only the headers in CREDENTIALHEADERS and COOKIEHEADERS are withheld. A caller-supplied header that carries a credential under some other name — X-API-Key, X-Vault-Token, or any bespoke token header — still follows a redirect to another origin, matching the behavior of curl's CURLOPTHTTPHEADER. If you set such a header, do not enable redirect following for requests that carry it, or scope it to a single request whose destination you control.

Workarounds

Set Mechanize#redirectok = false and handle redirects explicitly, or avoid requestheaders= for credentials and pass them per-request only to hosts you intend to authenticate to.

Credit

Reported by @SnailSploit.

Other sources

The Mechanize library is used for automating interaction with websites. Prior to 2.14.1, Mechanize sends caller-supplied credential headers to a different host after an HTTP redirect. Mechanize#requestheaders= is reapplied by Mechanize::HTTP::Agent#requestaddheaders even after Mechanize::HTTP::Agent#responseredirect strips per-request headers, and the protected header lists omit Proxy-Authorization and Cookie2. An attacker who controls a redirect target can capture bearer tokens or session cookies supplied through requestheaders= or the per-request headers argument, while Mechanize#cookiejar and Mechanize::HTTP::AuthStore are not affected. This issue is fixed in version 2.14.1.

— MITRE

Affected Software

2 affected componentsFixes available
rubygems/mechanize<2.14.1
rubygems/mechanize<2.14.1
2.14.1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rubygems/mechanize to a version that resolves this vulnerability.

    Fixed in 2.14.1
  2. Upgrade

    Upgrade mechanize to a version that resolves this vulnerability.

    Fixed in 2.14.1
  3. Configuration

    Set Mechanize#redirect_ok = false and handle redirects explicitly.

    Mechanize redirect_ok = false

Event History

Oct 8, 2026
CVE Published
via MITRE·09:27 PM
Data Sourced
via MITRE·09:27 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·10:09 PM
Data Sourced
via GitHub·10:09 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which applications are exposed to credential leakage?

Applications using Mechanize versions before 2.14.1 are exposed if they supply bearer tokens, session cookies, or other credential headers through request_headers= or a per-request headers argument and follow a redirect to another host.

2

What does an attacker need to exploit this issue?

An attacker needs to control the redirect target. They can capture caller-supplied credential headers when Mechanize follows a redirect from the original host to that target.

3

Are credentials managed by Mechanize itself affected?

No. Credentials stored in Mechanize#cookie_jar and Mechanize::HTTP::AuthStore are not affected by this issue.

4

What should be done if the application uses affected header mechanisms?

Upgrade Mechanize to version 2.14.1. Until then, avoid sending credentials through request_headers= or per-request headers when requests might follow redirects to another host.

5

How can I identify potentially affected usage?

Review Mechanize code for request_headers= and per-request headers arguments, especially uses of Proxy-Authorization, Cookie2, bearer-token headers, or session-cookie headers. Usage is potentially affected when redirects can cross to a different host.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203