GHSA-g7m4-839x-ch6v: spomky-labs/otphp Unbounded Digits Parameter Vulnerability

HIGH
CWE-369 CWE-1284
Published
Advisory Summary

GHSA-g7m4-839x-ch6v is a HIGH unbounded digits parameter vulnerability (CWE-369: Divide By Zero) affecting spomky-labs/otphp libraries in the Packagist ecosystem. The issue involves unbounded digits parameter in a provisioning uri triggers an uncaught divisionbyzeroerror in otp generation. Remediation is available by upgrading affected packages to version 11.4.3.

GHSA-g7m4-839x-ch6v at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-g7m4-839x-ch6v
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-369: Divide By Zero
Affected Product spomky-labs/otphp
Package Ecosystem Packagist
Published Date
Last Updated

How to Fix GHSA-g7m4-839x-ch6v

To remediate this vulnerability, upgrade all affected spomky-labs/otphp dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

spomky-labs/otphp fixed: 11.4.3
Upgrade spomky-labs/otphp to 11.4.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for spomky-labs/otphp

How to Check if You Are Affected

To determine whether your application is affected by GHSA-g7m4-839x-ch6v, inspect your project dependencies for spomky-labs/otphp:

inspect dependencies for spomky-labs/otphp

Analyze the terminal output to locate any version of spomky-labs/otphp in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 11.4.3), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-369: Divide By Zero, where the product divides a value by zero. In spomky-labs/otphp, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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

GHSA-g7m4-839x-ch6v Affected spomky-labs/otphp Versions

1 component(s)
Fixed Versions:
11.4.3
Product / Package Ecosystem Affected Versions Fixed Version
spomky-labs/otphp
Packagist
< 11.4.3
11.4.3

References

Frequently Asked Questions

What is GHSA-g7m4-839x-ch6v?
GHSA-g7m4-839x-ch6v is a security vulnerability in spomky-labs/otphp involving Unbounded digits parameter in a provisioning URI triggers an uncaught DivisionByZeroError in OTP generation under CWE-369: Divide By Zero.
Which spomky-labs/otphp versions are affected?
Affected versions include releases prior to 11.4.3 across affected packages: spomky-labs/otphp.
What version fixes GHSA-g7m4-839x-ch6v?
Upgrading to 11.4.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is spomky-labs/otphp affected?
Yes, spomky-labs/otphp is affected in releases prior to 11.4.3. Upgrade your dependency to 11.4.3 or later.
What CWE is associated with GHSA-g7m4-839x-ch6v?
GHSA-g7m4-839x-ch6v is classified under CWE-369: Divide By Zero (The product divides a value by zero.).
How can I check Packagist dependencies for GHSA-g7m4-839x-ch6v?
Run the dependency tree command: 'inspect dependencies for spomky-labs/otphp'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-g7m4-839x-ch6v",
  "modified" : "2026-06-18T20:45:48Z",
  "published" : "2026-06-18T20:45:47Z",
  "aliases" : [ ],
  "summary" : "spomky-labs/otphp: Unbounded digits parameter in a provisioning URI triggers an uncaught DivisionByZeroError in OTP generation",
  "details" : "## Summary\n\nThe `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`.\n\n## Impact\n\n`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).\n\nMeasured threshold on PHP 8.3: `digits = 30` works, `digits >= 40` throws `DivisionByZeroError: Modulo by zero`.\n\n## Affected component\n\n- `src/OTP.php:353-357` — `digits` parameter callback (no upper bound)\n- `src/OTP.php:283` — `$code % (10 ** $this->getDigits())`\n\n## Proof of concept\n\n```php\nuse OTPHP\\Factory;\nuse OTPHP\\InternalClock;\n\n$otp = Factory::loadFromProvisioningUri(\n    'otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&digits=50',\n    new InternalClock()\n);\n$otp->at(0); // DivisionByZeroError: Modulo by zero (escapes catch (\\Exception))\n```\n\n## Remediation\n\nEnforce 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`.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "spomky-labs/otphp"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "11.4.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Spomky-Labs/otphp/security/advisories/GHSA-g7m4-839x-ch6v"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/spomky-labs/otphp/GHSA-g7m4-839x-ch6v.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Spomky-Labs/otphp"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1284", "CWE-369" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-18T20:45:47Z",
    "nvd_published_at" : null
  }
}