GHSA-2mwr-xjcg-37j7: Infoleak

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.

Affected Software

1 affected componentFixes available
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
Advisory Published
via GitHub·10:09 PM
Data Sourced
via GitHub·10:09 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which configurations are exposed to credential leakage?

Clients that set sensitive default headers through Mechanize#request_headers= are exposed when a request is redirected to a different host. This includes Authorization headers, which were specifically intended to be stripped but could be reapplied from agent state.

2

Which headers can be sent to the redirected host?

Authorization, Proxy-Authorization, and Cookie2 may be forwarded on a cross-host redirect when supplied as request headers. The original stripping logic covered only Authorization and Cookie, and request_headers= bypassed that stripping entirely.

3

Are credentials stored in Mechanize's cookie jar or HTTP authentication store affected?

No. Cookies in Mechanize#cookie_jar and credentials in Mechanize::HTTP::AuthStore are looked up for each URI and do not follow redirects 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