{"id":"GHSA-jp94-3292-c3xv","summary":"Devise has an Open Redirect via Unvalidated `request.referrer` in Timeoutable Session Timeout Handler","details":"## Summary\n\nWhen 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.\n\n## Details\n\nThe vulnerable code is in `lib/devise/failure_app.rb`:\n\n```ruby\ndef redirect_url\n  if warden_message == :timeout\n    flash[:timedout] = true if is_flashing_format?\n\n    path = if request.get?\n      attempted_path          # safe: server-side value from warden options\n    else\n      request.referrer        # UNSAFE: HTTP Referer header, attacker-controlled\n    end\n\n    path || scope_url\n  else\n    scope_url\n  end\nend\n```\n\nThis is passed directly to `redirect_to`:\n\n```ruby\ndef redirect\n  store_location!\n  # ...\n  redirect_to redirect_url   # redirect_url may be an external attacker URL\nend\n```\n\nThe 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.\n\nBy contrast, Devise's `store_location_for` method (used elsewhere) correctly sanitizes URLs via `extract_path_from_location`, which strips the scheme and host.\n\n## Impact\n\n- 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.\n- The redirect happens transparently via a trusted domain (the target app's domain), bypassing browser phishing warnings.\n- An attacker can redirect victims to a fake login page to harvest credentials (phishing), or to malicious download sites.\n\n_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.\n\n## Patches\n\nThis is patched in Devise v5.0.4. Users should upgrade as soon as possible.\n\n## Workaround\n\nNone 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.","aliases":["CVE-2026-40295"],"modified":"2026-09-10T03:51:06.249835585Z","published":"2026-05-08T15:41:47Z","database_specific":{"cwe_ids":["CWE-601"],"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-05-08T15:41:47Z","nvd_published_at":"2026-05-22T20:16:34Z"},"references":[{"type":"WEB","url":"https://github.com/heartcombo/devise/security/advisories/GHSA-jp94-3292-c3xv"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40295"},{"type":"WEB","url":"https://github.com/heartcombo/devise/commit/025fe2124f9928766fc46520e999633b598d0360"},{"type":"PACKAGE","url":"https://github.com/heartcombo/devise"},{"type":"WEB","url":"https://github.com/rubysec/ruby-advisory-db/blob/master/gems/devise/CVE-2026-40295.yml"}],"affected":[{"package":{"name":"devise","ecosystem":"RubyGems","purl":"pkg:gem/devise"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"5.0.4"}]}],"versions":["0.1.0","0.1.1","0.2.0","0.2.1","0.2.2","0.2.3","0.3.0","0.4.0","0.4.1","0.4.2","0.4.3","0.5.0","0.5.1","0.5.2","0.5.3","0.5.4","0.5.5","0.5.6","0.6.0","0.6.1","0.6.2","0.6.3","0.7.0","0.7.1","0.7.2","0.7.3","0.7.4","0.7.5","0.8.0","0.8.1","0.8.2","0.9.0","0.9.1","0.9.2","1.0.0","1.0.1","1.0.10","1.0.11","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","1.1.5","1.1.6","1.1.7","1.1.8","1.1.9","1.1.pre","1.1.pre2","1.1.pre3","1.1.pre4","1.1.rc0","1.1.rc1","1.1.rc2","1.2.0","1.2.1","1.2.rc","1.2.rc2","1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.4.1","1.4.2","1.4.3","1.4.5","1.4.7","1.4.8","1.4.9","1.5.0","1.5.0.rc1","1.5.1","1.5.2","1.5.3","1.5.4","2.0.0","2.0.0.rc","2.0.0.rc2","2.0.1","2.0.2","2.0.4","2.0.5","2.0.6","2.1.0","2.1.0.rc","2.1.0.rc2","2.1.2","2.1.3","2.1.4","2.2.0","2.2.0.rc","2.2.1","2.2.2","2.2.3","2.2.4","2.2.5","2.2.6","2.2.7","2.2.8","3.0.0","3.0.0.rc","3.0.1","3.0.2","3.0.3","3.0.4","3.1.0","3.1.0.rc2","3.1.1","3.1.2","3.2.0","3.2.1","3.2.2","3.2.3","3.2.4","3.3.0","3.4.0","3.4.1","3.5.1","3.5.10","3.5.2","3.5.3","3.5.4","3.5.5","3.5.6","3.5.7","3.5.8","3.5.9","4.0.0","4.0.0.rc1","4.0.0.rc2","4.0.1","4.0.2","4.0.3","4.1.0","4.1.1","4.2.0","4.2.1","4.3.0","4.4.0","4.4.1","4.4.2","4.4.3","4.5.0","4.6.0","4.6.1","4.6.2","4.7.0","4.7.1","4.7.2","4.7.3","4.8.0","4.8.1","4.9.0","4.9.1","4.9.2","4.9.3","4.9.4","5.0.0","5.0.0.rc","5.0.1","5.0.2","5.0.3"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-jp94-3292-c3xv/GHSA-jp94-3292-c3xv.json","last_known_affected_version_range":"\u003c= 5.0.3"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"}]}