Summary
FileRise exposed users' existing TOTP secrets via the /api/totp_setup.php endpoint when invoked from a session that had only passed the password check.
An attacker who knows a victim's password could retrieve the live TOTP secret, generate valid one-time codes without the victim's device, and complete MFA verification to gain a fully authenticated session.
Affected context
This vulnerability affects FileRise instances using TOTP-based multi-factor authentication where:
- Users authenticate with a password and then complete TOTP verification.
- The
/api/totp_setup.phpendpoint is reachable in the "pending_login_user" state (password verified, TOTP not yet verified). - Existing TOTP configuration is not treated as a non-retrievable secret and is instead decrypted and reused during setup.
Under these conditions, an attacker who has learned a user's password can leverage the flawed setup flow to recover the user's TOTP secret.
Exploit preconditions
- Attack surface: Application login/API flow, specifically
/api/totp_setup.phpand/api/totp_verify.php. - Required access:
- Ability to establish a session that has successfully passed the password check (knowledge of the victim's password).
- Network access to the FileRise web UI or API (typically over HTTPS).
- Trigger point:
- Invoke
/api/totp_setup.phpwhile the target account already has TOTP configured and the session state ispending_login_user. - Extract the TOTP secret from the QR PNG response.
- Generate a one-time code and submit it to
/api/totp_verify.php. - Why exploitation is possible:
- The TOTP setup endpoint decrypts and returns the existing TOTP secret instead of refusing or generating a non-reusable value when MFA is already configured.
- The TOTP secret is treated as recoverable data and exposed to the client during an intermediate authentication state, enabling reconstruction of valid TOTP codes.
Why this happens
The core issue is a failure to protect sensitive authentication secrets and to enforce proper access control on MFA configuration workflows.
The /api/totp_setup.php endpoint is callable from a partially authenticated state and, when TOTP is already configured, decrypts and re-uses the existing secret, embedding it in a QR PNG returned to the client.
This behavior aligns with:
- CWE-200: Exposure of Sensitive Information to an Unauthorized Actor — the TOTP seed, which should be treated as non-recoverable, is exposed to anyone who can reach this state.
- CWE-287/CWE-306: Improper Authentication / Missing Authentication for Critical Function — accessing a critical function (MFA secret handling) without requiring full, second-factor verification.
Conceptually, the system conflates "password-verified" with "fully authenticated", and fails to enforce that TOTP enrollment and the TOTP secret itself must never be retrievable once set.
Potential impact
- Full account takeover for any user whose password an attacker has obtained, even if TOTP is enabled.
- Effective bypass of TOTP-based multi-factor authentication, negating its security benefits.
- Persistence of access as long as the TOTP secret remains unchanged or not revoked.
- Potential compromise of administrative or high-privilege accounts, depending on deployment.
General mitigation guidance
Mitigation patterns revolve around treating MFA secrets as non-recoverable credentials and hardening MFA-related workflows:
- Design TOTP enrollment so that once a secret is configured, it is never decrypted or displayed again; instead, require re-enrollment with a new secret when necessary.
- Ensure that any endpoint handling MFA secrets or setup is accessible only from a fully authenticated context and, where appropriate, requires an additional re-authentication (e.g., password re-entry plus existing second factor).
- Implement strict server-side checks that distinguish between "login in progress" and "fully authenticated" and restrict sensitive operations to the latter.
- Store TOTP secrets using secure storage mechanisms and interfaces that do not support direct retrieval by application clients.
- Apply least privilege to API endpoints: design them to perform minimal necessary operations and never return raw secrets or equivalent material.
How teams detect issues like this
High-level detection approaches for similar flaws include:
- Static analysis and code scanning:
- Flag endpoints that read or decrypt MFA secrets and verify that no code paths return these values to clients.
- Identify API routes callable from partially authenticated states that perform critical account or authentication operations.
- Code review practices:
- Review authentication and MFA workflow diagrams and code paths to ensure that each step has clearly defined authorization requirements.
- Look for any functionality that exposes QR codes, keys, or tokens after initial setup and verify that it either rotates secrets or blocks access once configured.
- Policy and testing:
- Establish security requirements that MFA seeds and recovery materials are write-only from the client perspective.
- Add integration tests that simulate a password-only session and verify that no MFA setup or secret-recovery endpoints can be used to obtain authentication material.
- Automated review tools and SAST/DAST can be configured with rules to highlight responses containing patterns indicative of keys or seeds, especially in authentication-related paths.

