# GHSA-g7m4-839x-ch6v: spomky-labs/otphp: Unbounded digits parameter in a provisioning URI triggers an uncaught DivisionByZeroError in OTP generation

- Severity: High (CVSS:4.0, scored by GitHub) `CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-06-18T20:45:47.000Z
- Modified: 2026-09-10T03:50:49.441Z
- Weaknesses: CWE-369, CWE-1284

## 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` — `digits` parameter callback (no upper bound)
- `src/OTP.php:283` — `$code % (10 ** $this->getDigits())`

## Proof of concept

```php
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`.

(As written by GitHub Advisory Database.)

## Affected

- spomky-labs/otphp (Packagist): before 11.4.3

## References

- <https://github.com/Spomky-Labs/otphp/security/advisories/GHSA-g7m4-839x-ch6v> (web)
- <https://github.com/FriendsOfPHP/security-advisories/blob/master/spomky-labs/otphp/GHSA-g7m4-839x-ch6v.yaml> (web)
- <https://github.com/Spomky-Labs/otphp> (package)

## Sources

- GitHub Advisory Database: [GHSA-g7m4-839x-ch6v](https://github.com/advisories/GHSA-g7m4-839x-ch6v), CC-BY-4.0, modified 2026-09-10

---

Page: https://cve.day/GHSA-g7m4-839x-ch6v · Whole record: https://cve.day/GHSA-g7m4-839x-ch6v.json · Rebuilt by cve.day 2026-11-25T22:56:32.125Z
