Oct 9, 2026·7 min read·61 visits
Mechanize prior to 2.14.1 fails to prevent caller-supplied global credentials from being transmitted to untrusted hosts during cross-origin HTTP redirections, exposing sensitive credentials to third parties.
Ruby Mechanize prior to version 2.14.1 contains an information disclosure vulnerability. When executing cross-origin HTTP redirects, global headers configured on the Mechanize agent (such as Authorization or Session Cookies) are dynamically re-applied to the subsequent request, bypassing the internal header-stripping logic. An attacker who controls a redirection endpoint can capture sensitive bearer tokens or cookies.
The Ruby Mechanize library, prior to version 2.14.1, contains an information disclosure vulnerability where caller-supplied credential headers are forwarded to external hosts following HTTP redirections. Mechanize is an automation and web-scraping framework designed to simulate browser behavior, handle session cookies, and manage state across multiple HTTP transactions. Because scraping agents often follow redirections automatically, the boundary between trusted origins and untrusted destinations must be strictly maintained.
The flaw exists within the redirection logic managed by the Mechanize::HTTP::Agent class. When a client application configures global headers or per-request credentials, these secrets are retained and re-applied to requests initiated during redirect chains. If a redirection points to a third-party domain, the agent fails to isolate these headers, transmitting sensitive data such as Authorization, Proxy-Authorization, Cookie, and Cookie2 headers to unverified external endpoints.
This behavior violates the basic principles of the Same-Origin Policy (SOP). It allows any intermediary or target server in a redirection chain to capture authorization tokens and session keys intended exclusively for the original server. The issue represents a critical flaw in applications that scrape user-submitted URLs or traverse untrusted web endpoints while maintaining authenticated sessions.
The technical root cause of this vulnerability lies in the structural separation of concerns between per-request state and persistent agent-level state in lib/mechanize/http/agent.rb. When a developer configures default headers using the Mechanize#request_headers= setter, these headers are saved to the instance variable @request_headers. During an initial request, these values are merged into the request payload.
Upon encountering an HTTP redirect (such as a 301, 302, or 307 status code), the library executes Mechanize::HTTP::Agent#response_redirect. This method contains sanitization logic that strips sensitive headers like Authorization and Cookie when the target URI differs from the current URI. However, this sanitization only mutates the temporary, per-request header dictionary passed as an argument. It does not alter the persistent @request_headers configuration on the agent instance.
When the agent attempts to fetch the target of the redirection, it initiates a new HTTP request and invokes #request_add_headers. This method iterates over the unmodified @request_headers hash and unconditionally re-applies all configurations back into the outgoing request. As a result, headers that were stripped during the redirect phase are silently re-inserted prior to transmission over the network.
Additionally, the blacklist used to identify sensitive headers in older versions was incomplete. It did not include standard headers like Proxy-Authorization or Cookie2. Furthermore, the library evaluated host matches solely by comparing hostname strings (new_uri.host == page.uri.host). This comparison ignored variations in port numbers and protocol schemes, allowing credential leaks to occur when downgrading from HTTPS to plaintext HTTP on the same host.
The following block demonstrates the vulnerable state restoration inside lib/mechanize/http/agent.rb before the security patch was applied. Note how @request_headers are read and written directly to the request object, rendering the stripping logic in #response_redirect ineffective.
# VULNERABLE: lib/mechanize/http/agent.rb
# In older versions, every fetch operation re-applied `@request_headers` from scratch.
def request_add_headers(request, headers = {})
# Global headers are unconditionally added to every single request,
# including intermediate redirect hops where they should have been stripped.
@request_headers.each do |k, v|
request[k] = v
end
headers.each do |k, v|
request[k] = v
end
endThe patch implemented in version 2.14.1 introduces a mechanism to control when global headers are merged. Instead of dynamically re-applying global state on every request execution, the library now merges @request_headers exactly once when a top-level request is initiated by the user. Subsequent hops in a redirect chain set apply_request_headers to false.
The following code block highlights the remediation implemented in the patched version. The origin comparison was also updated to conform with RFC 6454 rules, checking the protocol scheme, hostname, and port number to detect cross-origin boundaries accurately.
# PATCHED: lib/mechanize/http/agent.rb
# Global headers are merged only once at the beginning of the transaction.
def fetch(uri, method = :get, headers = {}, params = [], referer = nil,
redirect_ok = @redirect_ok, apply_request_headers = true)
# Merge global request headers only if this is the initial request
headers = merge_request_headers(headers) if apply_request_headers
# ... request processing and redirect logic
end
# The comparison is expanded to ensure scheme, host, and port are validated.
def crosses_origin?(from_uri, to_uri)
to_uri.scheme != from_uri.scheme ||
to_uri.host != from_uri.host ||
to_uri.port != from_uri.port
endBy ensuring that apply_request_headers is disabled for redirection loops and authentication retries, the updated library prevents the restoration of stripped credentials. The blacklisted headers list was also expanded to include Proxy-Authorization and Cookie2 in the constant lists.
Exploitation of this vulnerability requires that an attacker induce a Mechanize-based client to send an authenticated request to a domain under the attacker's control, or to a trusted site containing an open redirect vulnerability. In a typical scenario, a target application uses Mechanize to fetch and parse external content, passing a user-supplied URL as a parameter while carrying administrative or session tokens in the global headers.
If the attacker hosts a page that issues an HTTP 302 redirect pointing to their own server, Mechanize follows the redirect. Because of the bug in #request_add_headers, the original Authorization and Cookie headers are re-injected and sent directly to the attacker-controlled server. The attacker can log these headers to capture the authentication bearer tokens or session cookies.
This behavior also occurs through HTML <meta> refresh tags found in scraped pages. If Mechanize parses a page containing <meta http-equiv="refresh" content="0;url=http://attacker.com">, it triggers an internal redirect mechanism via #response_follow_meta_refresh. In vulnerable versions, this flow does not isolate the origin, causing the agent to include global authentication headers when querying the attacker's web page.
The security impact of this vulnerability is classified as Medium with a CVSS v3.1 base score of 6.8. The primary risk is the loss of confidentiality of highly sensitive session and authentication secrets. Because Mechanize is frequently used to scrape websites, access APIs, or perform automated testing, these leaked credentials often represent critical user accounts or API keys.
The CVSS vector breakdown (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N) highlights specific environmental factors. The attack vector is Network (AV:N), indicating that exploitation can occur over the internet. Attack Complexity is High (AC:H) because the attacker must find or control a redirection target that the Mechanize instance can be persuaded to fetch.
The Scope is Changed (S:C) because credentials belonging to one origin are transmitted to a different security domain. The impact is limited to Confidentiality (C:H) as the flaw allows reading the headers but does not directly modify data on the client or compromise system availability. However, the stolen credentials can subsequently be used to gain unauthorized access to target systems, escalating the total impact.
The most complete remediation is upgrading the Mechanize gem to version 2.14.1 or later. This release restructures the header lifecycles to ensure that global credentials are not persistently re-applied to redirect requests. Developers can update their dependency files to enforce this minimum version.
# Update Mechanize within the project environment
bundle update mechanizeIf immediate upgrading is not possible, developers should avoid using the global Mechanize#request_headers= setter to assign sensitive information like API tokens and authorization headers. Instead, credentials should be supplied dynamically as argument overrides for specific, targeted #get or #post requests. This pattern prevents the agent from storing the secrets in its long-lived state.
Alternatively, automatic redirection can be disabled by setting agent.redirect_ok = false. Under this configuration, the application must catch redirection responses manually, inspect the target location, and explicitly verify that the destination belongs to a trusted domain before executing a separate, sanitized request.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
mechanize Mechanize Project | < 2.14.1 | 2.14.1 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-200 |
| Attack Vector | Network (High Complexity) |
| CVSS v3.1 | 6.8 (Medium) |
| Exploit Status | Proof of Concept (PoC) available |
| CISA KEV Status | Not Listed |
| Remediation Status | Patched in v2.14.1 |
The product exposes sensitive information to an actor who is not authorized to have access to that information.
An operating system command injection vulnerability (CWE-78) exists in GeoNode versions prior to 5.1.0. The vulnerability occurs in the vector upload processing pipeline when handling user-supplied geospatial files. By supplying a crafted layer name containing shell metacharacters, an authenticated attacker with basic data upload privileges can execute arbitrary commands on the underlying server or container hosting the GeoNode application and Celery worker processes.
GeoNode versions prior to 5.0.3 contain an unrestricted file upload vulnerability (CWE-434) within the document and dataset ingestion architecture. Authenticated low-privileged users can bypass upload validation via direct REST API interactions, file extension masquerading, metadata mutation via PATCH requests, or malicious archive submissions. This allows attackers to store and serve dangerous file types, alter on-disk file references, or trigger path traversal and resource exhaustion during archive extraction.
CVE-2026-55649 is a stored Cross-Site Scripting (XSS) vulnerability in GeoNode versions prior to 5.0.3. The flaw exists because document abstract metadata fields are ingested via the metadata management pipeline and stored in the backend database without HTML sanitization or input neutralization. An authenticated attacker with privileges to create or edit document metadata can inject arbitrary HTML and JavaScript payloads into these fields. When another user, such as an administrator, views the affected document page or catalog listing, the unencoded payload is rendered into the Document Object Model (DOM) and executes within the victim's browser session.
CVE-2026-55622 (GHSA-qx75-2p3r-pwm5) is an improper access control vulnerability (CWE-284) in Canonical LXD and LXC Incus (tracked as GHSA-c9f5-j9c3-mhrg). In multi-tenant deployments utilizing project-based isolation, the REST API handler for instance creation via POST /1.0/instances verifies that the authenticated user has authorization in the destination project specified by the query parameter, but fails to verify whether the user holds read or view permissions for the source instance when executing a copy operation across projects. Consequently, an authenticated client restricted to a single project can clone instances or snapshots from unauthorized projects into their own project, resulting in complete disclosure of the target instance filesystem and embedded credentials.
An authorization bypass vulnerability in Canonical LXD (tracked as GHSA-7mr3-28h5-m5vx and CVE-2026-55621, and as GHSA-64f3-v33m-w89f in Linux Containers Incus) allows an authenticated user with restricted project access to copy custom storage volumes and volume snapshots from unauthorized projects. The flaw resides in the storagePoolVolumesPost REST API handler, which verifies permissions on the destination project but fails to check whether the caller holds view entitlements on the source project or volume specified in the request body.
A missing authorization and configuration validation vulnerability in Canonical LXD and LXC Incus allows authenticated users within restricted projects to bypass project security boundaries. By smuggling prohibited low-level configuration directives (such as raw.lxc or raw.qemu) inside instance snapshots or backup archives, an attacker can restore these configurations within a restricted project and execute arbitrary commands with root privileges on the underlying host operating system.