Summary
OpenEMR does not sufficiently limit repeated TOTP submissions, allowing an attacker with a valid password to make repeated attempts to guess the six-digit MFA code. If the application is reachable and these attempts are not throttled or locked out, an attacker may bypass MFA and access the account.
Affected context
The issue affects OpenEMR authentication paths that accept TOTP codes without effective rate limiting or lockout. The described paths include main_screen.php and the OAuth2 authorization flow, where hidden credentials may be resubmitted with repeated requests. OpenEMR versions before 8.5.0 are identified as affected.
Exploit preconditions
- Attack surface: An OpenEMR login or OAuth2 authorization endpoint reachable by the attacker
- Required access: A valid account password
- Trigger point: Repeated TOTP submissions during authentication
- Why exploitation is possible: Attempts are not sufficiently rate-limited or locked out, allowing automated guessing of the six-digit code
Why this happens
The application does not adequately restrict the rate of authentication attempts involving TOTP. This maps to CWE-307: Improper Restriction of Excessive Authentication Attempts. Without effective throttling, lockout, or equivalent controls, an attacker who has a valid password can repeatedly submit candidate MFA codes.
Potential impact
- An attacker may bypass the account's MFA protection
- Unauthorized access to the affected user's account could occur
- Sensitive patient or operational information could be exposed or altered, depending on account privileges
- A compromised account could be used to access additional application functions
General mitigation guidance
Mitigations generally focus on limiting repeated authentication attempts consistently across all login and authorization flows.
- Apply rate limits and progressive delays to failed TOTP attempts
- Use bounded lockout or step-up verification controls that resist automated guessing while accounting for denial-of-service risks
- Avoid relying on client-side state or resubmitted hidden credentials to enforce authentication policy
- Apply controls consistently across web and OAuth2 authentication paths
- Keep MFA and application privileges scoped to the user's needs
How teams detect issues like this
Detection approaches may include:
- Monitoring for repeated failed TOTP attempts across accounts, sessions, and source addresses
- Reviewing authentication handlers for missing throttling, lockout, or shared attempt counters
- Using static analysis and code review to identify MFA verification paths without server-side attempt controls
- Enforcing authentication policies in tests and CI checks, including coverage of alternate OAuth2 and web login flows
- Reviewing logs for unusually high request rates or repeated authorization attempts

