Skip to content

fix: prevent scientific notation in timestamp on low-precision PHP en…#419

Open
mehmet-yoti wants to merge 3 commits into
masterfrom
Release/4.5.2
Open

fix: prevent scientific notation in timestamp on low-precision PHP en…#419
mehmet-yoti wants to merge 3 commits into
masterfrom
Release/4.5.2

Conversation

@mehmet-yoti

Copy link
Copy Markdown
Contributor

…vironments (#418)

On PHP FPM environments with non-default precision ini settings (≤12), casting a large float to string could produce scientific notation (e.g. 1.78E+12) instead of a plain integer, causing Yoti signature verification to fail with 401 MESSAGE_SIGNING.

Replace (string)(round(microtime(true) * 1000)) with sprintf('%.0F', microtime(true) * 1000) which forces a plain decimal string regardless of the precision ini setting, and drops the redundant round() since %.0F already rounds to zero decimal places.

Tests added to verify plain integer output under precision=12 and precision=8 (via @dataProvider), and to assert the timestamp falls within the correct Unix-millisecond range under low precision without masking scientific notation via an early (int) cast.

Fixes #417

…vironments (#418)

On PHP FPM environments with non-default precision ini settings (≤12),
casting a large float to string could produce scientific notation
(e.g. 1.78E+12) instead of a plain integer, causing Yoti signature
verification to fail with 401 MESSAGE_SIGNING.

Replace (string)(round(microtime(true) * 1000)) with
sprintf('%.0F', microtime(true) * 1000) which forces a plain decimal
string regardless of the precision ini setting, and drops the redundant
round() since %.0F already rounds to zero decimal places.

Tests added to verify plain integer output under precision=12 and
precision=8 (via @dataProvider), and to assert the timestamp falls
within the correct Unix-millisecond range under low precision without
masking scientific notation via an early (int) cast.

Fixes #417

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a timestamp formatting bug in SignedRequestStrategy::createQueryParams() where low precision ini settings can cause float-to-string conversion to emit scientific notation, breaking request signature verification.

Changes:

  • Format the millisecond timestamp using sprintf('%.0F', microtime(true) * 1000) to force a plain integer string under low precision settings.
  • Add PHPUnit coverage to assert the timestamp remains a digit-only integer string for low precision values and remains within the expected Unix-millisecond range.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Http/AuthStrategy/SignedRequestStrategy.php Changes timestamp generation to avoid scientific notation under low precision settings.
tests/Http/AuthStrategy/SignedRequestStrategyTest.php Adds regression tests for low-precision timestamp formatting and validates Unix-millisecond range behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Http/AuthStrategy/SignedRequestStrategyTest.php
Comment thread tests/Http/AuthStrategy/SignedRequestStrategyTest.php
Comment thread tests/Http/AuthStrategy/SignedRequestStrategyTest.php Outdated
Comment thread tests/Http/AuthStrategy/SignedRequestStrategyTest.php Outdated
Add ini_set()/ini_get() failure checks with markTestSkipped() so tests
are skipped rather than silently passing as false-positives when the
runtime disallows changing the precision ini setting. Cast restored
precision to string defensively. Remove : void return types from new
test methods for consistency with the rest of the test file.
…idation

Newer Guzzle 7.x patch versions reject relative URIs (e.g. '/') when no
base_uri is configured, throwing InvalidArgumentException before the
MockHandler is reached. Replace with an absolute URI so the mock handler
intercepts correctly on all Guzzle 7.x versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SignedRequestStrategy timestamp may use scientific notation on PHP 8.4, causing signing failures

2 participants