Cloudanix VulnDB

CVE-2024-8796

Medium · 5.3

Devise-Two-Factor Authentication Uses Insufficient Default OTP Shared Secret Length

CVSS

5.3

EPSS

0.6%

Published

Sep 17, 2024

CISA due date

—

Cloudanix analysis

Schedule a fix SSVC: Track

Some applications may have created multi-factor login codes using secrets that were slightly weaker than recommended, so affected users should be upgraded and their MFA setup refreshed.

Chainable
Exploitation
Remote Authenticated
Attacker needs
Low Privilege
Complexity
High
Impact
Privilege Gain
Component
Library
Class
Cryptographic Weakness
Remediation
Upgrade
Effort
Medium
Patch risk
Medium

What it actually does

Devise-Two-Factor generated Time-based One-Time Password (TOTP) shared secrets with 120 bits of entropy under the default configuration, below the 128-bit minimum recommended by RFC 4226. The weakness reduces the theoretical search space for an attacker attempting to recover or guess a user’s MFA shared secret and then generate valid TOTP codes. This does not directly disclose credentials, bypass MFA by itself, or provide remote code execution; practical exploitation would typically require other account-compromise conditions such as a known password, access to observed one-time codes, weak rate limiting, or stolen application data. Existing TOTP secrets generated by vulnerable versions may remain weak until rotated or re-enrolled.

Why it matters to the business

Applications relying on affected Devise-Two-Factor versions may have MFA protections that are slightly weaker than expected, which can increase account-takeover risk if attackers already possess user passwords or other authentication material. The practical risk is limited by the still-large 120-bit secret space, low EPSS score, no known public exploit maturity, and no CISA KEV listing, but the issue can create compliance, audit, and customer-trust concerns because MFA secret generation does not meet the referenced cryptographic minimum. Organizations with broad Ruby/Rails dependency usage should address this through normal dependency patching and MFA-secret rotation planning.

How an attack unfolds

An attacker would first identify an application using a vulnerable Devise-Two-Factor release and target accounts protected by TOTP MFA. The attacker would still need a way to pass the first authentication factor, such as stolen credentials, phishing, credential stuffing, or session compromise. To abuse this flaw specifically, the attacker would attempt to derive or guess the user’s TOTP shared secret, potentially using observed TOTP codes, stolen database material, implementation details, or repeated online guesses if rate limiting is weak. Because the generated secret is 120 bits rather than 128 bits, exhaustive search is theoretically easier, but remains computationally impractical in most real-world conditions. If the attacker succeeds in determining the shared secret, they can generate valid TOTP codes and complete MFA challenges until the secret is rotated.

How to fix it

Upgrade Devise-Two-Factor to a fixed release, preferably version 6.0.0 or later where applicable, or to a build containing commit cc6f34423d9c6af9f3e02be478c3c40dc7462e19. Review dependency manifests and lockfiles to ensure no application is pinned to version 1.0.0 or any version >= 4.0.0 and < 6.0.0. Because secrets generated before the fix may remain 120-bit, plan to rotate existing TOTP shared secrets by requiring users to re-enroll MFA after the upgrade, prioritizing administrators, privileged users, and high-risk accounts. Ensure MFA verification has strict rate limiting, account lockout or throttling, replay prevention, and alerting for repeated failed TOTP attempts. If immediate upgrade is not possible, increase compensating controls around login monitoring, credential stuffing protection, session anomaly detection, and privileged-account access review.

How to confirm the fix worked

Confirm the application is no longer using an affected Devise-Two-Factor version by checking dependency lockfiles, package inventory, software composition analysis results, or runtime gem versions. Validate that the installed package includes commit cc6f34423d9c6af9f3e02be478c3c40dc7462e19 or is at version 6.0.0 or later where applicable. Test new MFA enrollment after the upgrade and verify that newly generated TOTP secrets meet the expected entropy/length requirements. Confirm that users enrolled before the upgrade have been re-enrolled or had their TOTP secrets rotated. Review authentication controls to verify rate limiting and alerting apply to TOTP validation failures. Re-run dependency scans after deployment and ensure CI/CD policies prevent reintroduction of affected versions.

Typical attack path

  1. Identify a Ruby/Rails application using Devise-Two-Factor version 1.0.0 or versions >= 4.0.0 and < 6.0.0.
  2. Obtain or guess a valid username and password through a separate technique such as phishing, credential reuse, or password spraying.
  3. Collect authentication context, observed TOTP values, or stolen application data that could help attack the MFA shared secret.
  4. Attempt to recover or guess the TOTP shared secret, benefiting from the reduced 120-bit entropy compared with the 128-bit minimum.
  5. Generate valid TOTP codes for the victim account if the shared secret is recovered.
  6. Authenticate successfully and perform account takeover actions such as data access, privilege changes, persistence setup, or fraudulent transactions.

How to detect it

There is no reliable log entry or artifact that uniquely proves exploitation of this cryptographic weakness. Investigations should focus on account-takeover patterns around MFA-protected logins. Review application authentication logs, identity-provider logs, web access logs, and audit trails for repeated TOTP failures, high-volume MFA attempts, successful MFA immediately after many failures, successful logins from new geographies or user agents, impossible-travel events, credential-stuffing activity followed by MFA success, and privileged actions shortly after unusual authentication. Look for MFA enrollment, reset, or recovery events near suspicious logins. If database or backup access was suspected, investigate whether TOTP shared secrets could have been exposed and correlate that access with later successful MFA events. Because exploitation would usually require valid primary credentials, also review password reset events, failed password attempts, known credential stuffing indicators, session creation anomalies, and changes to email, recovery methods, API keys, or privileged roles.

What your security team should do

  • Inventory all applications that use Devise-Two-Factor and identify versions 1.0.0 or >= 4.0.0 and < 6.0.0.
  • Upgrade to Devise-Two-Factor 6.0.0 or later, or a build containing commit cc6f34423d9c6af9f3e02be478c3c40dc7462e19.
  • Rotate or re-enroll TOTP MFA secrets generated while affected versions were in use, prioritizing administrators and sensitive accounts.
  • Verify login throttling, TOTP failure monitoring, account lockout controls, and anomalous-login alerting are enabled.
  • Search authentication logs for suspicious MFA activity, especially repeated TOTP failures followed by successful logins from unusual locations or devices.
  • Treat this as a normal-priority cryptographic remediation unless paired with active account-takeover indicators, because EPSS is low, exploit maturity is reported as none, and it is not listed in CISA KEV.
  • Add dependency checks to CI/CD or software composition analysis policies to block affected Devise-Two-Factor versions.

The record

Under the default configuration, Devise-Two-Factor versions 1.0.0 or >= 4.0.0 & < 6.0.0 generate TOTP shared secrets that are 120 bits instead of the 128-bit minimum defined by [RFC 4226](https://datatracker.ietf.org/doc/html/rfc4226). Using a shared secret shorter than the minimum to generate a multi-factor authentication code could make it easier for an attacker to guess the shared secret and generate valid TOTP codes.

Affected packages

Ecosystem Package Introduced Fixed
RubyGems devise-two-factor 1.0.0 No fix
RubyGems devise-two-factor 2.2.0 6.0.0
RubyGems devise-two-factor 4.0.0 6.0.0
Chainguard gitlab-rails-ce-assets-18.1 0 18.1.6-r1
Chainguard gitlab-rails-ce-assets-18.2 0 18.2.8-r1
Chainguard gitlab-rails-ce-assets-18.3 0 18.3.5-r0
Chainguard gitlab-rails-ce-assets-18.4 0 18.4.3-r0
Chainguard gitlab-rails-ce-assets-18.5 0 18.5.1-r0
Chainguard gitlab-rails-ce-assets-18.6 0 18.6.1-r1
Chainguard gitlab-rails-ce-assets-18.7 0 18.7.0-r0
Chainguard gitlab-rails-ce-assets-fips-18.1 0 18.1.6-r2
Chainguard gitlab-rails-ce-assets-fips-18.2 0 18.2.8-r2
Chainguard gitlab-rails-ce-assets-fips-18.3 0 18.3.5-r2
Chainguard gitlab-rails-ce-assets-fips-18.4 0 18.4.3-r3
Chainguard gitlab-rails-ce-assets-fips-18.5 0 18.5.1-r2
Chainguard gitlab-rails-ce-assets-fips-18.6 0 18.6.1-r2
Chainguard gitlab-rails-ce-assets-fips-18.7 0 18.7.0-r0
Chainguard gitlab-rails-ce-doc-18.1 0 18.1.6-r1
Chainguard gitlab-rails-ce-doc-18.2 0 18.2.8-r1
Chainguard gitlab-rails-ce-doc-18.3 0 18.3.5-r0
Chainguard gitlab-rails-ce-doc-18.4 0 18.4.3-r0
Chainguard gitlab-rails-ce-doc-18.5 0 18.5.1-r0
Chainguard gitlab-rails-ce-doc-18.6 0 18.6.2-r0
Chainguard gitlab-rails-ce-doc-18.7 0 18.7.0-r0
Chainguard gitlab-rails-ce-doc-fips-18.1 0 18.1.6-r2
Chainguard gitlab-rails-ce-doc-fips-18.2 0 18.2.8-r2
Chainguard gitlab-rails-ce-doc-fips-18.3 0 18.3.5-r2
Chainguard gitlab-rails-ce-doc-fips-18.4 0 18.4.3-r3
Chainguard gitlab-rails-ce-doc-fips-18.5 0 18.5.1-r2
Chainguard gitlab-rails-ce-doc-fips-18.6 0 18.6.1-r2
Chainguard gitlab-rails-ce-doc-fips-18.7 0 18.7.0-r0
Debian:11 ruby-devise-two-factor 0 No fix
Debian:12 ruby-devise-two-factor 0 No fix
Debian:13 ruby-devise-two-factor 0 No fix
Ubuntu:16.04:LTS ruby-devise-two-factor 0 No fix
Ubuntu:20.04:LTS ruby-devise-two-factor 0 No fix
Ubuntu:22.04:LTS ruby-devise-two-factor 0 No fix
Ubuntu:Pro:16.04:LTS ruby-devise-two-factor 0 No fix
Ubuntu:Pro:20.04:LTS ruby-devise-two-factor 0 3.1.0-2ubuntu0.1~esm1
Ubuntu:Pro:22.04:LTS ruby-devise-two-factor 0 4.0.0-2ubuntu0.1~esm1
gem devise-two-factor 1.0.0 No fix
gem devise-two-factor 4.0.0 6.0.0

Related vulnerabilities