CVE-2024-0227: Devise two factor Remote Code Execution Vulnerability

MODERATE
Advisory Identifier: GHSA-chcr-x7hc-8fp8
CVSS 5.0
CWE-307
Published
Advisory Summary

CVE-2024-0227 is a MODERATE (CVSS 5.0) remote code execution vulnerability (CWE-307: Improper Restriction of Excessive Authentication Attempts) affecting Devise two factor libraries in the RubyGems ecosystem. The issue involves devise-two-factor vulnerable to brute force attacks. Remediation is available in the latest vendor maintenance releases.

CVE-2024-0227 at a Glance

CVE Identifier CVE-2024-0227
GHSA Identifier GHSA-chcr-x7hc-8fp8
Severity MODERATE
CVSS v3.1 Base Score 5.0
CWE Classification CWE-307: Improper Restriction of Excessive Authentication Attempts
Affected Product Devise two factor
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 5.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:L).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2024-0227

To remediate this vulnerability, upgrade all affected Devise two factor dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

devise-two-factor fixed: Latest secure release
Upgrade devise-two-factor to Latest secure release
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for devise-two-factor

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-0227, inspect your project dependencies for Devise two factor:

inspect dependencies for devise-two-factor

Analyze the terminal output to locate any version of Devise two factor in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than the patched release), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-307: Improper Restriction of Excessive Authentication Attempts, where the product does not implement sufficient measures to prevent multiple failed authentication attempts within a short time frame. In Devise two factor, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Advisory withdrawn The backing CVE has been rejected Devise-Two-Factor does not throttle or otherwise restrict login attempts at the server by default. When combined with the Time-based One Time Password algorithm's (TOTP) inherent entropy limitations, it's possible for an attacker to bypass the 2FA mechanism through brute-force attacks. ### Impact If a user's username and password have already been compromised an attacker would be able to try possible TOTP codes and see if they can hit a lucky collision to log in as that user. The user under attack would not necessarily know that their account has been compromised. ### Patches Devise-Two-Factor has not released any fixes for this vulnerability. This library is open-ended by design and cannot solve this for all applications natively. It's recommended that any application leveraging Devise-Two-Factor implement controls at the application level to mitigate this threat. A non-exhaustive list of possible mitigations can be found below. #### Mitigations 1. Use the `lockable` strategy from Devise to lock a user after a certain number of failed login attempts. See https://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Lockable for more information. 2. Configure a rate limit for your application, especially on the endpoints used to log in. One such library to accomplish this is [rack-attack](https://rubygems.org/gems/rack-attack). 3. When displaying authentication errors hide whether validating a username/password combination failed or a two-factor code failed behind a more generic error message. ### Acknowledgements Christian Reitter ([Radically Open Security](https://www.radicallyopensecurity.com/)) and Chris MacNaughton ([Centauri Solutions](https://centauri.solutions))

CVE-2024-0227 Affected Devise two factor Versions

1 component(s)
Product / Package Ecosystem Affected Versions Fixed Version
devise-two-factor
RubyGems
≥ 1.0.0
≤ 5.0.0

References

Frequently Asked Questions

What is CVE-2024-0227?
CVE-2024-0227 is a security vulnerability in Devise two factor involving Devise-Two-Factor vulnerable to brute force attacks under CWE-307: Improper Restriction of Excessive Authentication Attempts.
Which Devise two factor versions are affected?
Affected versions include releases prior to current release patches across affected packages: devise-two-factor.
What version fixes CVE-2024-0227?
Upgrading to current release patches (or the latest patched release for your respective branch) resolves the vulnerability.
Is devise-two-factor affected?
Yes, devise-two-factor is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of CVE-2024-0227?
CVE-2024-0227 has a CVSS v3.1 base score of 5.0 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:L.
What CWE is associated with CVE-2024-0227?
CVE-2024-0227 is classified under CWE-307: Improper Restriction of Excessive Authentication Attempts (The product does not implement sufficient measures to prevent multiple failed authentication attempts within a short time frame.).
How can I check RubyGems dependencies for CVE-2024-0227?
Run the dependency tree command: 'inspect dependencies for devise-two-factor'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-chcr-x7hc-8fp8",
  "modified" : "2024-03-20T15:34:05Z",
  "published" : "2024-01-12T15:13:05Z",
  "withdrawn" : "2024-03-19T22:33:55Z",
  "aliases" : [ "CVE-2024-0227" ],
  "summary" : "Devise-Two-Factor vulnerable to brute force attacks",
  "details" : "### Advisory withdrawn\nThe backing CVE has been rejected\n\nDevise-Two-Factor does not throttle or otherwise restrict login attempts at the server by default. When combined with the Time-based One Time Password algorithm's (TOTP) inherent entropy limitations, it's possible for an attacker to bypass the 2FA mechanism through brute-force attacks.\n\n### Impact\n\nIf a user's username and password have already been compromised an attacker would be able to try possible TOTP codes and see if they can hit a lucky collision to log in as that user. The user under attack would not necessarily know that their account has been compromised.\n\n### Patches\n\nDevise-Two-Factor has not released any fixes for this vulnerability. This library is open-ended by design and cannot solve this for all applications natively. It's recommended that any application leveraging Devise-Two-Factor implement controls at the application level to mitigate this threat. A non-exhaustive list of possible mitigations can be found below.\n\n#### Mitigations\n\n1. Use the `lockable` strategy from Devise to lock a user after a certain number of failed login attempts. See https://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Lockable for more information.\n2. Configure a rate limit for your application, especially on the endpoints used to log in. One such library to accomplish this is [rack-attack](https://rubygems.org/gems/rack-attack).\n3. When displaying authentication errors hide whether validating a username/password combination failed or a two-factor code failed behind a more generic error message.\n\n### Acknowledgements\n\nChristian Reitter ([Radically Open Security](https://www.radicallyopensecurity.com/)) and Chris MacNaughton ([Centauri Solutions](https://centauri.solutions))",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "devise-two-factor"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.0.0"
      }, {
        "last_affected" : "5.0.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/devise-two-factor/devise-two-factor/security/advisories/GHSA-chcr-x7hc-8fp8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-0227"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/devise-two-factor/devise-two-factor"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/devise-two-factor/CVE-2024-0227.yml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-307" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-01-12T15:13:05Z",
    "nvd_published_at" : "2024-01-11T20:15:44Z"
  }
}