Summary
Horilla HRMS 1.4.0 contains a logic flaw in its one-time password (OTP) verification that treats missing OTP input as equivalent to an expired OTP value.
By omitting the otp field from a POST request after an OTP has expired, an attacker can satisfy the equality check and bypass two-factor authentication entirely, potentially gaining unauthorized access to sensitive HR data and administrative functionality.
Affected context
This vulnerability affects deployments of Horilla HRMS that have two-factor authentication enabled and rely on OTP-based verification during login or sensitive operations.
The flaw manifests in the OTP comparison logic where both the server-side OTP (which becomes None when expired) and the user-supplied OTP (omitted from the request and thus also None) are compared directly.
In environments where administrative or privileged accounts protect sensitive HR, payroll, or employee records via OTP, this logic error can undermine the entire second factor.
Exploit preconditions
- Attack surface: Public or internal web interface where OTP-based two-factor authentication is enforced (login flows, step-up verification, or critical actions).
- Required access: Knowledge of or ability to guess/obtain a valid username and password for a target account; network access to the Horilla HRMS instance.
- Trigger point: Submission of an authentication or verification POST request without the otp field after the backend has marked the OTP as expired and set its value to
None. - Why exploitation is possible: The code compares
user_otp == otpwithout differentiating between "no value provided" and "expired/stored value isNone", so equality evaluation passes when both areNone, effectively treating absence of OTP as a valid second factor.
Why this happens
The underlying issue is a faulty authentication logic pattern where the application directly compares a stored OTP value with user input using a loose equality check.
When the OTP expires, the server represents the absence of a valid OTP as None, but the same None value is also used to represent the case where the client omits the otp parameter.
This collapses distinct states—"no OTP provided," "OTP expired," and "invalid OTP"—into an indistinguishable condition in the comparison.
This behavior maps to CWE-287: Improper Authentication, as the authentication mechanism fails to correctly validate the second factor and grants access despite incomplete verification.
Potential impact
- Unauthorized bypass of two-factor authentication for user and administrator accounts.
- Compromise of sensitive HR data, including personal, salary, and performance information.
- Manipulation, creation, or deletion of employee records and roles.
- Abuse of administrative functions, such as changing user permissions or configuring the system for further attacks.
- Use of compromised HRMS accounts as a pivot point for social engineering or broader environment compromise.
General mitigation guidance
Effective mitigation focuses on making OTP state handling explicit and separating "missing input" from "invalid or expired token" cases.
Recommended defensive patterns include:
- Treating omission of the OTP parameter as an automatic verification failure, regardless of server-side state.
- Using distinct sentinel values or explicit state flags for "expired", "not generated", and "valid" OTPs rather than overloading
None. - Implementing strict verification flows where both a valid, non-empty OTP and a valid server-side record must be present before comparison.
- Centralizing authentication and factor-checking logic to avoid duplicated, inconsistent patterns across endpoints.
- Applying defense-in-depth controls such as rate limiting and anomaly detection around OTP verification to reduce brute-force or automated abuse.
How teams detect issues like this
Detection can focus on both code-level signals and runtime behavior patterns:
- Static analysis and code review:
- Flag authentication code paths where security decisions rely on direct equality checks of potentially
null/Nonevalues. - Examine OTP or second-factor handling for ambiguous states (e.g., same value representing both "not provided" and "invalid/expired").
- Review controller logic for conditions where access is granted even when required parameters are missing.
- Automated tooling:
- Configure SAST tools with custom rules for improper authentication patterns, especially equality checks between user input and state that can be
Noneor default values. - Use unit and integration tests that explicitly cover edge cases such as missing parameters, expired OTPs, and reused tokens.
- Runtime monitoring:
- Log and analyze authentication events where OTP fields are missing yet logins succeed.
- Create alerts for suspicious login patterns, such as repeated successful logins without corresponding OTP submissions.

