SDK-2819 prevent scientific notation in timestamp on low-precision#418
Merged
Conversation
…vironments
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
There was a problem hiding this comment.
Pull request overview
This PR hardens SignedRequestStrategy::createQueryParams() against PHP environments with low precision ini settings where casting a large float to string can yield scientific notation, which breaks Yoti request signature verification.
Changes:
- Replace float-to-string timestamp generation with
sprintf('%.0F', microtime(true) * 1000)to force a plain decimal integer string. - Add PHPUnit coverage to ensure timestamp formatting stays as a plain integer under low precision settings and remains within the expected Unix-millisecond range.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Http/AuthStrategy/SignedRequestStrategy.php |
Switches timestamp formatting to a sprintf-based approach that avoids scientific notation under low precision. |
tests/Http/AuthStrategy/SignedRequestStrategyTest.php |
Adds tests validating plain-integer timestamp formatting under low precision and validating millisecond-range correctness. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.