Skip to content

Commit b75f47d

Browse files
authored
GHSA/SYNC: 1 new devise advisory (#1055)
1 parent c648bbf commit b75f47d

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

gems/devise/CVE-2026-40295.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
gem: devise
3+
cve: 2026-40295
4+
ghsa: jp94-3292-c3xv
5+
url: https://github.com/heartcombo/devise/security/advisories/GHSA-jp94-3292-c3xv
6+
title: Devise has an Open Redirect via Unvalidated `request.referrer`
7+
in Timeoutable Session Timeout Handler
8+
date: 2026-05-08
9+
description: |
10+
## Summary
11+
12+
When the `Timeoutable` module is enabled in Devise, the
13+
`FailureApp#redirect_url` method returns `request.referrer` — the
14+
HTTP `Referer` header, which is attacker-controllable — without
15+
validation for any non-GET request that results in a session timeout.
16+
An attacker who hosts a page with an auto-submitting cross-origin
17+
form can cause a victim with an expired Devise session to be
18+
redirected to an arbitrary external URL. This contrasts with the
19+
GET timeout path (which uses server-side `attempted_path`) and
20+
Devise's own `store_location_for` mechanism (which strips external
21+
hosts via `extract_path_from_location`), both of which are protected;
22+
only the non-GET timeout redirect path is unprotected.
23+
24+
## Details
25+
26+
The vulnerable code is in `lib/devise/failure_app.rb`:
27+
28+
```ruby
29+
def redirect_url
30+
if warden_message == :timeout
31+
flash[:timedout] = true if is_flashing_format?
32+
33+
path = if request.get?
34+
attempted_path # safe: server-side value from warden options
35+
else
36+
request.referrer # UNSAFE: HTTP Referer header, attacker-controlled
37+
end
38+
39+
path || scope_url
40+
else
41+
scope_url
42+
end
43+
end
44+
```
45+
46+
This is passed directly to `redirect_to`:
47+
48+
```ruby
49+
def redirect
50+
store_location!
51+
# ...
52+
redirect_to redirect_url # redirect_url may be an external attacker URL
53+
end
54+
```
55+
56+
The GET timeout path uses `attempted_path`, which is set server-side
57+
by Warden and cannot be influenced by the client. The `store_location!`
58+
method also only runs for GET requests, so no session-based protection
59+
is applied on POST timeouts.
60+
61+
By contrast, Devise's `store_location_for` method (used elsewhere)
62+
correctly sanitizes URLs via `extract_path_from_location`, which
63+
strips the scheme and host.
64+
65+
## Impact
66+
67+
- Victims with expired sessions who click any attacker-crafted link
68+
or visit an attacker page with an auto-submitting form are redirected
69+
to an arbitrary external URL.
70+
- The redirect happens transparently via a trusted domain (the target
71+
app's domain), bypassing browser phishing warnings.
72+
- An attacker can redirect victims to a fake login page to harvest
73+
credentials (phishing), or to malicious download sites.
74+
75+
_Note_: Rails' built-in open-redirect protection does not mitigate
76+
this issue. `Devise::FailureApp` is an `ActionController::Metal`
77+
app with its own isolated copy of the relevant redirect configuration,
78+
so `config.action_controller.action_on_open_redirect = :raise` (and
79+
the older `raise_on_open_redirects` setting) do not reach it.
80+
81+
## Patches
82+
83+
This is patched in Devise v5.0.4. Users should upgrade as soon as possible.
84+
85+
## Workaround
86+
87+
None beyond upgrading. If an upgrade is not immediately possible, the
88+
same changes from the patch commit can be applied as a monkey-patch
89+
in a Rails initializer (`Devise::FailureApp#redirect_url` and
90+
`Devise::Controllers::StoreLocation#extract_path_from_location`).
91+
Remove the monkey-patch after upgrading.
92+
cvss_v3: 6.1
93+
patched_versions:
94+
- ">= 5.0.4"
95+
related:
96+
url:
97+
- https://www.cve.org/CVERecord?id=CVE-2026-40295
98+
- https://github.com/heartcombo/devise/releases/tag/v5.0.4
99+
- https://github.com/heartcombo/devise/blob/v5.0.4/CHANGELOG.md#504---2026-05-08
100+
- https://github.com/heartcombo/devise/commit/9ea459de9aec5f1217ad738c58e0d23fb9f5beaa
101+
- https://github.com/heartcombo/devise/commit/025fe2124f9928766fc46520e999633b598d0360
102+
- https://github.com/heartcombo/devise/security/advisories/GHSA-jp94-3292-c3xv
103+
- https://github.com/advisories/GHSA-jp94-3292-c3xv

0 commit comments

Comments
 (0)