Skip to content

GHSA-2jx3-65f3-xr8r spomky-labs/otphp: Mass-assignment in Factory::loadFromProvisioningUri lets a hostile provisioning URI corrupt OTP state or leak an uncaught TypeError

MediumCVSS 6.9
Published
Updated
Exploit status
No public exploit known
Technology
PHP

Description

Summary

OTPHP\Factory::loadFromProvisioningUri() parses an attacker-supplied otpauth:// URI and forwards every query key to OTP::setParameter($key, $value). setParameter() resolves the name with property_exists($this, $parameter) and performs a dynamic write $this->{$parameter} = $value (src/OTP.php:196-197). Because the query keys are entirely controlled by whoever produced the URI, a URI can target the internal properties of the OTP object that are not meant to be set from a URI: parameters, issuer, label, issuer_included_as_parameter, and (on TOTP) the readonly clock. This is an instance of object property mass-assignment (CWE-915).

Impact

The Factory is documented as the entry point for third-party provisioning URIs (e.g. QR codes from Microsoft 365 / Google Authenticator). An application that loads such a URI is exposed to:

  • State corruption. A URI such as otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&parameters[foo]=bar overwrites the whole internal $parameters array that createFromSecret() primed (period, algorithm, digits, epoch). The resulting object is silently unusable: getProvisioningUri(), getDigits(), at(), verify() then throw ParameterNotFoundException.
  • Uncaught TypeError escaping the documented exception type. A URI such as otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&issuer_included_as_parameter=notabool assigns a string to a typed bool property and raises a TypeError. The try/catch in loadFromProvisioningUri() only wraps Url::fromString(); createOTP() and populateOTP() run outside it, so the TypeError (and Error on the readonly clock) escapes past the documented InvalidProvisioningUriException, breaking callers that catch only the documented type.
  • Label/issuer validation bypass. parameters[label]=hijacked stores a label into the parameters array without running the label validation callback (keyed on label, not parameters). getLabel() and getParameter('label') then disagree — a confused-deputy risk.

Affected component

  • src/OTP.php:187-201 — setParameter() dynamic property write
  • src/Factory.php:50-55 — populateParameters() forwarding all query keys

Proof of concept

use OTPHP\Factory;

// State corruption
$otp = Factory::loadFromProvisioningUri(
    'otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&parameters[foo]=bar',
    $clock
);
$otp->getProvisioningUri(); // ParameterNotFoundException: Parameter "period" does not exist

// Uncaught TypeError
Factory::loadFromProvisioningUri(
    'otpauth://totp/Alice?secret=JBSWY3DPEHPK3PXP&issuer_included_as_parameter=notabool',
    $clock
); // TypeError escapes InvalidProvisioningUriException

Remediation

Restrict the keys accepted from a provisioning URI to a known allow-list of public OTP parameters, and never let a URI key resolve to an internal object property via property_exists. Route all URI-sourced values through the validated parameter map only.

Upgrade path

1 package: 1 fixed.

PackageAffectedFixed inStatus
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

ProductAffected versionsFixed 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
ProductAffected versionsFixed 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