CVE-2026-40295: Devise Open Redirect Vulnerability in Timeoutable Session Timeout Handler

devise Updated 08 May 2026

Summary

08/05/2026
Yes i
Moderate
6.1

CVE-2026-40295: Devise has an Open Redirect via Unvalidated request.referrer in Timeoutable Session Timeout Handler. Affects devise versions < 5.0.4. Fixed in 5.0.4. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

Devise is a flexible authentication solution for Rails based on Warden. It provides various modules to handle user authentication, including the Timeoutable module, which allows sessions to expire after a period of inactivity. This functionality is crucial for maintaining security in web applications, but it also introduces potential vulnerabilities if not properly managed.

Vulnerability Detail

The vulnerability arises from the Timeoutable module in Devise, where the FailureApp#redirect_url method returns the request.referrer without validation for non-GET requests that result in a session timeout. This allows an attacker to exploit the HTTP Referer header, redirecting users with expired sessions to arbitrary external URLs. The implications include phishing attacks, where users could be redirected to fake login pages, or malicious sites that could compromise user data. The vulnerability is particularly concerning because it bypasses browser phishing warnings, as the redirect appears to originate from a trusted domain.

How To Fix

Latest published version: 5.0.4 as of 22 Oct 2026

gem install devise -v 5.0.4

The newest release already contains this fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If an immediate upgrade is not possible, a temporary workaround involves applying a monkey patch in a Rails initializer. You can override the redirect_url method in Devise::FailureApp to sanitize the request.referrer. Here’s an example of how to implement the monkey patch:

# config/initializers/devise_monkey_patch.rb
module Devise
  class FailureApp
    def redirect_url
      if warden_message == :timeout
        flash[:timedout] = true if is_flashing_format?
        path = if request.get?
          attempted_path
        else
          extract_path_from_location(request.referrer) # Sanitize referrer
        end
        path || scope_url
      else
        scope_url
      end
    end
  end
end

Conclusion

The CVE-2026-40295 vulnerability in the Devise authentication library poses a significant risk due to its potential for exploitation via session timeouts. Users are strongly advised to upgrade to version 5.0.4 or later to mitigate this risk. In the interim, a monkey patch can be applied as a temporary solution.

See every vulnerability recorded for devise →

Share this vulnerability

FAQ

CVE-2026-40295 is a vulnerability in the Devise authentication library that allows attackers to exploit session timeouts and redirect users to arbitrary external URLs.

You can check if your application is affected by using the Vulert playground at Vulert Scanner, which allows you to monitor and alert for open-source vulnerabilities without requiring installation.

The vulnerability can lead to phishing attacks, where users are redirected to fake login pages, or to malicious sites that could compromise user data.

You can upgrade Devise by running the command gem update devise in your terminal. Ensure to test your application after the upgrade.

Yes, you can apply a monkey patch in a Rails initializer to sanitize the request.referrer. Refer to the provided code snippet for implementation.

Related vulnerabilities

Recent vulnerabilities recorded for devise.

How To Fix

Latest published version: 5.0.4 as of 22 Oct 2026

gem install devise -v 5.0.4

The newest release already contains this fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback