Summary
ApostropheCMS contains an authentication flaw where bearer tokens associated with logins that have not completed TOTP/MFA checks are mistakenly treated as fully authenticated sessions.
In deployments using @apostrophecms/login-totp or custom afterPasswordVerified requirements, this allows attackers who obtain or generate such partial tokens to bypass multi-factor authentication and access protected resources as if MFA were satisfied.
Affected context
The vulnerability occurs in ApostropheCMS instances that:
- Use bearer token authentication via the middleware in
@apostrophecms/express - Have TOTP/MFA enabled through
@apostrophecms/login-totpor any customafterPasswordVerifiedlogin requirement - Rely on MongoDB-backed login token documents to represent authentication state
The issue arises when an incomplete login token—where the password has been validated but the additional factor has not—can still satisfy the middleware's database query and be treated as a fully authenticated bearer token.
Exploit preconditions
- Attack surface: HTTP(S) endpoints protected by ApostropheCMS bearer token authentication.
- Required access: Ability to obtain or submit a bearer token corresponding to a login flow where the password was successfully verified but TOTP/MFA or other
afterPasswordVerifiedchecks were not completed. - Trigger point: Sending API or web requests with the affected bearer token in the Authorization header to routes guarded by the authentication middleware.
- Why exploitation is possible: The MongoDB query used by the bearer token middleware does not correctly ensure that all post-password-verification requirements (such as TOTP/MFA) have been satisfied, so tokens from partially completed login flows are accepted as if they represented full authentication.
Why this happens
This vulnerability stems from an authorization logic error in the bearer token authentication middleware.
The MongoDB query that looks up login tokens fails to distinguish between:
- Tokens created after password verification but before completion of MFA or other
afterPasswordVerifiedchecks, and - Tokens representing fully authenticated sessions.
As a result, the middleware incorrectly treats any token that matches the partial criteria as fully valid.
This maps primarily to CWE-287: Improper Authentication, because the system does not correctly enforce the required authentication steps, and secondarily to CWE-305: Authentication Bypass by Primary Weakness, since the bypass arises from flawed verification logic rather than cryptographic weakness.
Abstractly, this is an insecure pattern where a single token or flag is used for multiple authentication states, and downstream code fails to check that the state reflects completion of all required factors.
Potential impact
- Attackers may bypass TOTP/MFA or custom
afterPasswordVerifiedchecks and gain access using only a password-verified token. - Compromise of user accounts protected by multi-factor authentication.
- Escalation to administrative or editorial privileges if high-privilege accounts are targeted.
- Unauthorized content changes, data exposure, or manipulation of CMS-managed resources.
- Potential pivot into related systems or integrations that trust ApostropheCMS authentication.
General mitigation guidance
Mitigation focuses on enforcing complete authentication state before issuing or accepting bearer tokens:
- Ensure that login tokens used for bearer authentication are only created or marked as valid after all authentication steps (password plus TOTP/MFA or other secondary checks) are successfully completed.
- Represent authentication state explicitly in the data model, using distinct fields or token types for "password-verified" and "fully authenticated" sessions, and require the stronger state for API access.
- Centralize authentication logic so that bearer token validation reuses the same checks and invariants as interactive login flows.
- Apply the principle of least privilege to tokens: limit their scope, lifetime, and permissible actions so that a single logic error has reduced blast radius.
- Incorporate defense-in-depth controls such as IP-based alerts, unusual login detection, or rate limiting around token-based access to reduce exploitation opportunities.
How teams detect issues like this
Effective detection typically includes:
- Static analysis and code review:
- Look for authentication middleware that queries login or token collections without explicitly checking MFA-related fields or flags.
- Review MongoDB queries in authentication code paths for ambiguous criteria that do not differentiate partial and complete authentication states.
- Identify any code paths where tokens are generated or persisted before all required checks are finalized.
- Logging and monitoring:
- Log token creation events separately for password verification and full MFA completion, and alert on tokens used without corresponding MFA-complete events.
- Monitor for repeated use of tokens associated with incomplete login flows or unusually fast transitions from password verification to authenticated API usage.
- Automated tooling and policy enforcement:
- Use security-focused linters or custom rules to flag authentication logic that does not explicitly enforce secondary factors where configured.
- Integrate CI checks that prevent changes to authentication middleware unless they include validation of configured MFA or
afterPasswordVerifiedstates.

