CVE-2026-40295 — Vulnerability in devise — CVE Details
Devise has an Open Redirect via Unvalidated `request.referrer` in Timeoutable Session Timeout Handler
What Should I Do?
Address in Next Maintenance Window
Low exploitation probability (0.32%). Schedule for your next planned update.
Does your project use an affected devise version?
Paste your Gemfile.lock to check it for CVE-2026-40295 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.
Summary
Summary
When the Timeoutable module is enabled in Devise, the FailureApp#redirect_url method returns request.referrer — the HTTP Referer header, which is attacker-controllable — without validation for any non-GET request that results in a session timeout. An attacker who hosts a page with an auto-submitting cross-origin form can cause a victim with an expired Devise session to be redirected to an arbitrary external URL. This contrasts with the GET timeout path (which uses server-side attempted_path) and Devise's own store_location_for mechanism (which strips external hosts via extract_path_from_location), both of which are protected; only the non-GET timeout redirect path is unprotected.
Details
The vulnerable code is in lib/devise/failure_app.rb:
def redirect_url
if warden_message == :timeout
flash[:timedout] = true if is_flashing_format?
path = if request.get?
attempted_path # safe: server-side value from warden options
else
request.referrer # UNSAFE: HTTP Referer header, attacker-controlled
end
path || scope_url
else
scope_url
end
end
This is passed directly to redirect_to:
def redirect
store_location!
# ...
redirect_to redirect_url # redirect_url may be an external attacker URL
end
The GET timeout path uses attempted_path, which is set server-side by Warden and cannot be influenced by the client. The store_location! method also only runs for GET requests, so no session-based protection is applied on POST timeouts.
By contrast, Devise's store_location_for method (used elsewhere) correctly sanitizes URLs via extract_path_from_location, which strips the scheme and host.
Impact
- Victims with expired sessions who click any attacker-crafted link or visit an attacker page with an auto-submitting form are redirected to an arbitrary external URL.
- The redirect happens transparently via a trusted domain (the target app's domain), bypassing browser phishing warnings.
- An attacker can redirect victims to a fake login page to harvest credentials (phishing), or to malicious download sites.
Note: Rails' built-in open-redirect protection does not mitigate this issue. Devise::FailureApp is an ActionController::Metal app with its own isolated copy of the relevant redirect configuration, so config.action_controller.action_on_open_redirect = :raise (and the older raise_on_open_redirects setting) do not reach it.
Patches
This is patched in Devise v5.0.4. Users should upgrade as soon as possible.
Workaround
None beyond upgrading. If an upgrade is not immediately possible, the same changes from the patch commit can be applied as a monkey-patch in a Rails initializer (Devise::FailureApp#redirect_url and Devise::Controllers::StoreLocation#extract_path_from_location). Remove the monkey-patch after upgrading.
Advisory Timeline
- First published May 8, 2026 (202 days ago).
- Last revised September 10, 2026 — 125 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
gem install devise -v 5.0.4
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (1)
Affects 1 ecosystem: RubyGems (1).
| Package | Fixed In |
|---|---|
| devise RubyGems · Affected: 0.1.0, 0.1.1, 0.2.0, 0.2.1 (+168 more) | 5.0.4 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-601Open RedirectMITRE
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 6.1 score means for each attack dimension.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
References
- https://github.com/heartcombo/devise/security/advisories/GHSA-jp94-3292-c3xvWEB
- https://nvd.nist.gov/vuln/detail/CVE-2026-40295ADVISORY
- https://github.com/heartcombo/devise/commit/025fe2124f9928766fc46520e999633b598d0360WEB
- https://github.com/heartcombo/devisePACKAGE
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/devise/CVE-2026-40295.ymlWEB
Frequently Asked Questions
- What is CVE-2026-40295?
- Devise has an Open Redirect via Unvalidated `request.referrer` in Timeoutable Session Timeout Handler. This vulnerability has been assigned a severity rating of MEDIUM (CVSS score: 6.1/10).
- How do I check if my project is affected by CVE-2026-40295?
- CVE-2026-40295 affects devise. It has a 0.3% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-40295 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Exploitation requires specific conditions, or the impact is limited.
This is a below-median EPSS score — only 17.1% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.
Also Known As
Related CVEs
- CVE-2015-8314HIGH
Devise Gem for Ruby Unauthorized Access Using "Remember Me" Cookie
- CVE-2026-128084MEDIUM
sqlite3-ruby: Possible SQL query truncation when a string is 4 GiB or larger
- CVE-2026-32700MEDIUM
Devise has a confirmable "change email" race condition permits user to confirm email they have no access to
- CVE-2026-115472MEDIUM
Doorkeeper: When using public clients, any client can revoke any access token