GHSA-g7m4-839x-ch6v spomky-labs/otphp: Unbounded digits parameter in a provisioning URI triggers an uncaught DivisionByZeroError in OTP generation
- Published
- Updated
- Exploit status
- No public exploit known
- Technology
- PHP
Description
Summary
The digits parameter parsed from a provisioning URI is validated only with a lower bound ($value > 0) and has no upper bound (src/OTP.php:353-357). OTP generation computes $code % (10 ** $this->getDigits()) (src/OTP.php:283). When digits is large enough that 10 ** digits overflows PHP's integer range and the (int) cast yields 0 (around digits >= 40 on 64-bit PHP 8.x), the modulo operand becomes 0 and PHP raises a DivisionByZeroError.
Impact
OTPHP\Factory::loadFromProvisioningUri() forwards the attacker-controlled digits query value to setParameter('digits', $value), so a hostile URI such as otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&digits=50 produces an OTP object whose at(), now(), and verify() all throw DivisionByZeroError. Because DivisionByZeroError extends Error (not Exception), callers that guard OTP generation with a catch (\Exception) do not catch it, turning a malformed URI into an unhandled fatal error (denial of service of the verification path).
Measured threshold on PHP 8.3: digits = 30 works, digits >= 40 throws DivisionByZeroError: Modulo by zero.
Affected component
src/OTP.php:353-357—digitsparameter callback (no upper bound)src/OTP.php:283—$code % (10 ** $this->getDigits())
Proof of concept
use OTPHP\Factory;
use OTPHP\InternalClock;
$otp = Factory::loadFromProvisioningUri(
'otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&digits=50',
new InternalClock()
);
$otp->at(0); // DivisionByZeroError: Modulo by zero (escapes catch (\Exception))
Remediation
Enforce a sane upper bound on digits in the parameter validation callback (e.g. reject values above 8–10, the practical range for OTPs) so that an out-of-range value is rejected with a documented exception instead of producing an object that fails later with an uncatchable Error.
Upgrade path
1 package: 1 fixed.
| Package | Affected | Fixed in | Status |
|---|---|---|---|
| spomky-labs/otphp(Packagist) | < 11.4.3; = 1.0.1-stable; = 5.0.0; = 11.0.3 +57 more | 11.4.3 | Fixed |
Affected products
| Product | Affected versions | Fixed in |
|---|---|---|
| spomky-labs/otphp(Packagist) | < 11.4.3 | 11.4.3 |
| spomky-labs/otphp(Packagist) | = 1.0.1-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.1.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.1.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.2.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.2.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.2.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.3.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.4.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.4.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = 11.4.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = 5.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v1.0.0-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = v10.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v10.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v10.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v10.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v11.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v11.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v11.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v2.0.0-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = v2.0.1-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = v2.0.2-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = v3.0.0-stable | No fix listed |
Show 36 more
| Product | Affected versions | Fixed in |
|---|---|---|
| spomky-labs/otphp(Packagist) | = v3.0.1-stable | No fix listed |
| spomky-labs/otphp(Packagist) | = v3.1.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v3.1.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v4.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v4.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v4.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v4.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v4.0.4 | No fix listed |
| spomky-labs/otphp(Packagist) | = v5.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v6.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v6.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v6.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v6.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v6.0.4 | No fix listed |
| spomky-labs/otphp(Packagist) | = v7.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v7.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v7.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v7.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v7.0.4 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.1.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.2.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.3.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.3.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.3.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v8.3.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.0.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.0.0-alpha1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.0.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.0.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.0.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.1.0 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.1.1 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.1.2 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.1.3 | No fix listed |
| spomky-labs/otphp(Packagist) | = v9.1.4 | No fix listed |
References
- github.com vendor-advisory
- github.com
- github.com product
- github.com