Repository navigation
Conversation
…r value
RsaAnalyzer counted the modulus as 8 × octets and read the exponent with
unpack('l'), so leading zero octets (RFC 7518 §2 forbids them, Base64urlUInt)
let a key with n = 15 and e = 1 pass with no message. Both values are now read
as big-endian integers with BigInteger.
ESKeyAnalyzer checked the point with Curve::contains(), which reduces modulo p,
so a coordinate >= p passed while OpenSSL refuses the key. Coordinates are now
required to be lower than the field prime.
1 of 5 tasks
Member
|
Thank you @lav45 for the report and the fix. As a bug fix, it goes into 4.2.x, so it continues in #825: your commit is |
lav45
pushed a commit
to lav45/jwt-framework
that referenced
this pull request
Nov 10, 2026
"Resolves issue web-token#823" does not link a pull request to the issue: GitHub expects the keyword directly before the reference, and the word "issue" in between breaks it. web-token#824 targeted the default branch with that line and was never linked to web-token#823. The template now reads "Resolves #", and its comment says to repeat the keyword for each issue, since one keyword links only the reference that follows it.
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.
Target branch: 4.3.x
Resolves issue #823
Includes:
The defect
RsaAnalyzerandESKeyAnalyzerreport no message for keys that are weak or unusable (#823).checkModulus()counted the bits as 8 × the octet length ofn, andcheckExponent()readewithunpack('l', …): machine byte order, signed, first four octets. Leading zero octets were not stripped, although RFC7518 §2 (Base64urlUInt) requires the minimum number of octets. A key with
n= 15 ande= 1, written with leadingzero octets, gave no message: its length was counted as 2048 bits, and
e=00 00 00 01was read as 16777216.Ecc\Curve::contains(), which reduces modulo p. A coordinatey + pthat stillfits the coordinate length (always possible on P-521: 66 octets, p = 2^521 − 1) passed, while OpenSSL refuses the key,
so every verification with it fails.
The fix
RsaAnalyzerreadsnandeas big-endian unsigned integers (Util\BigInteger::createFromBinaryString()), andcompares the bit length of the modulus and the value of the exponent. An empty
noregivesThe modulus is not valid./The exponent is not valid., the messages already used for a value that is not astring.
ESKeyAnalyzerrequiresxandyto be lower than the field prime (SEC 1 §3.2.2.1, NIST SP 800-56A §5.6.2.3)before the on-curve check, with the new message
Invalid key. The components "x" and "y" shall be lower than the field prime.The length checks on octet strings (
x/yinESKeyAnalyzer,kinHSKeyAnalyzerandOctAnalyzer) are unchanged:these values are fixed-length octet strings, not Base64urlUInt.
Tests
Two tests in
tests/Component/KeyManagement/JWKAnalyzerTest.php, both failing without the fix:theRsaKeyWithLeadingZeroOctetsIsAnalyzedByItsValue:n= 15 ande= 1 with leading zero octets get the key lengthand exponent messages;
theEcKeyWithACoordinateAboveTheFieldPrimeIsRejected: a P-521 key withy + pgets the field prime message.PHPUnit, PHPStan, ECS, Rector and Deptrac pass with
ghcr.io/spomky-labs/phpqa:8.4.