spomky-labs/otphp Unbounded Digits Parameter Leads to Denial of Service
The spomky-labs/otphp library is vulnerable to a denial of service (GHSA-g7m4-839x-ch6v) where an unbounded 'digits' parameter in an otpauth provisioning URI causes a DivisionByZeroError, leading to unhandled fatal errors in applications trying to generate or verify OTPs.
The spomky-labs/otphp library, versions prior to 11.4.3, is affected by a high-severity denial-of-service vulnerability (GHSA-g7m4-839x-ch6v) concerning its handling of OTP provisioning URIs. This vulnerability, disclosed in June 2026, arises when the digits parameter within an otpauth URI is provided with an excessively large value (typically 40 or greater). The library's internal validation for this parameter only checks for a lower bound, lacking an upper bound. During OTP generation or verification, the calculation 10 ** digits overflows PHP's integer capacity on 64-bit systems, resulting in an implicit cast to 0. A subsequent modulo operation with this zero value triggers a DivisionByZeroError. Critically, this error extends PHP's Error class rather than Exception, meaning it bypasses typical try-catch (\Exception) blocks, leading to unhandled fatal errors and effectively causing a denial of service for any application component attempting to process the malformed OTP object.
Attack Chain
- An attacker crafts a malicious
otpauthprovisioning URI containing an unusually largedigitsparameter, for example,otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&digits=50. - A vulnerable PHP application, utilizing
spomky-labs/otphp(versions prior to 11.4.3), processes this URI, for instance, by callingOTPHP\Factory::loadFromProvisioningUri(). - The
loadFromProvisioningUri()function internalizes the attacker-controlleddigitsparameter, which bypasses validation due to the lack of an upper bound check. - Later, the application attempts to generate or verify an OTP by invoking methods like
at(),now(), orverify()on theOTPHP\OTPobject created from the malicious URI. - During the OTP calculation within
src/OTP.php:283, the expression10 ** $this->getDigits()is evaluated using the excessively largedigitsvalue. - On 64-bit PHP 8.x, for
digitsvalues around 40 or higher, the exponentiation10 ** digitsresults in an integer overflow, causing PHP to implicitly cast the result to0. - A subsequent modulo operation,
($code % 0), attempts to divide by zero, which triggers aDivisionByZeroError. - As
DivisionByZeroErroris a PHPError(not anException), it typically bypasses standard error handling, leading to an unhandled fatal error and causing a denial of service for the affected application component.
Impact
The vulnerability can lead to an application-level denial of service. When an application attempts to process a maliciously crafted otpauth URI, the internal DivisionByZeroError leads to an unhandled fatal error, effectively crashing the OTP generation or verification process. This means that users might be unable to log in, perform multi-factor authentication, or complete any transaction relying on OTPs, rendering the affected service partially or fully unavailable. While no specific victim counts are provided, any PHP application utilizing the vulnerable spomky-labs/otphp library for OTP functionality could be impacted.
Recommendation
- Upgrade the
spomky-labs/otphplibrary to version 11.4.3 or newer immediately to mitigate the vulnerability (GHSA-g7m4-839x-ch6v). - Deploy the Sigma rule "Detect GHSA-g7m4-839x-ch6v OTPHPH Vulnerability Exploitation Attempt" to your web application firewall (WAF) or intrusion detection system (IDS) to block web requests containing suspicious
otpauthURIs with largedigitsparameters. - Implement the Sigma rule "Detect Potential OTP Application Denial of Service (HTTP 5xx Response)" and tune it for high-volume HTTP 5xx responses on OTP-related endpoints as a general indicator of potential DoS.
- Enable comprehensive application logging for PHP errors and monitor for
DivisionByZeroErrormessages, particularly those originating fromspomky-labs/otphpcomponents.
Detection coverage 2
Detect GHSA-g7m4-839x-ch6v OTPHPH Vulnerability Exploitation Attempt
highDetects attempts to exploit the spomky-labs/otphp DivisionByZeroError vulnerability (GHSA-g7m4-839x-ch6v) by passing an otpauth URI with an excessively large 'digits' parameter (>=40) within a web request. This can lead to application denial of service.
Detect Potential OTP Application Denial of Service (HTTP 5xx Response)
mediumDetects HTTP 5xx server errors on web endpoints commonly associated with OTP verification. While generic, a spike can indicate a denial of service due to vulnerabilities like GHSA-g7m4-839x-ch6v or other application logic errors impacting OTP processing.
Detection queries are available on the platform. Get full rules →