# GHSA-g7m4-839x-ch6v: The `digits` parameter parsed from a provisioning URI is validated only with a lower bound (`$value > 0`) and has no upper bound

> An attacker can cause a denial of service in the OTP verification path by supplying a provisioning URI with an excessively large digits parameter, triggering an uncaught error.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 18 Jun 2026

## What is GHSA-g7m4-839x-ch6v?

GHSA-g7m4-839x-ch6v is a denial of service vulnerability in spomky-labs/otphp, published on 18 Jun 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official 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`.

## Which versions are affected by GHSA-g7m4-839x-ch6v?

2 open source packages ship an affected version, including spomky-labs/otphp.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `spomky-labs/otphp` | Packagist | All versions | 11.4.3 |
| `spomky-labs/otphp` | Packagist | All versions | 11.4.3 |

## How do I fix GHSA-g7m4-839x-ch6v?

Upgrade spomky-labs/otphp to 11.4.3 or later.

## Is GHSA-g7m4-839x-ch6v being exploited?

There is no known exploitation of GHSA-g7m4-839x-ch6v in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-g7m4-839x-ch6v and fix it if it is affected.

What it is: GHSA-g7m4-839x-ch6v is a denial of service vulnerability in spomky-labs/otphp, published on 18 Jun 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-g7m4-839x-ch6v in the wild and no public exploit code.

Affected packages and fixed versions:
- spomky-labs/otphp (Packagist): affected all versions; fixed in 11.4.3
- spomky-labs/otphp (Packagist): affected all versions; fixed in 11.4.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-g7m4-839x-ch6v/ (Markdown: https://insights.sbomify.com/GHSA-g7m4-839x-ch6v/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-g7m4-839x-ch6v

---
From sbomify Insights: https://insights.sbomify.com/GHSA-g7m4-839x-ch6v/
Summaries are generated and may contain mistakes; the official description above is the record.
