Skip to content

Merge release 4.3.0 into 5.0.x - #837

Merged
Spomky merged 58 commits into
5.0.xfrom
4.3.x-merge-up-into-5.0.x_zUT9LIP0
Nov 29, 2026
Merged

Spomky merged 58 commits into
5.0.xfrom
4.3.x-merge-up-into-5.0.x_zUT9LIP0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Release Notes for 4.3.0

Feature release (minor)

4.3.0

  • Total issues resolved: 32
  • Total pull requests resolved: 59
  • Total contributors: 2

bug

enhancement

Compliance,enhancement

Compliance,bug

DX

feature

Spomky and others added 30 commits November 8, 2026 22:44
…er reject

SDJWTIssuer issued SD-JWTs whose processed payload is deeper than the
64 levels of DisclosureProcessor, or whose Disclosures hold more JSON
values than the budget of BoundedJsonDecoder: the Holder and the
Verifier then refused them.

Before signing, the Issuer now parses an SD-JWT that has the payload,
the Disclosures, the serialization and the unprotected headers of the
one to issue, then processes it as SDJWT::select() does. Both bounds
come from the classes that enforce them, and such claims are refused
with an InvalidArgumentException.

Fixes #805
Disclosure::forObjectProperty() and Disclosure::forArrayElement() wrote
the JSON of any value, while Disclosure::fromString() decodes it with a
BoundedJsonDecoder: at most 4096 values, and at most 511 levels of
arrays and objects, the array of the Disclosure included. A value of 511
nested arrays, an object whose JSON has 511 levels, 300 arrays around an
object of 300 levels or a list of 4095 integers gave a Disclosure that
this library then rejected as "not valid JSON", and SDJWTIssuer issued
SD-JWTs that the Holder and the Verifier could not parse.

Both factories now decode the JSON of the Disclosure with a new
BoundedJsonDecoder before returning it, and refuse the value with an
InvalidArgumentException when the Disclosure cannot be parsed. The
levels are thus counted from the array of the Disclosure, for the arrays
and the objects of the value alike, and the bounds are those of the
parser.

Fixes #808
…bounds

fix(sd-jwt): create only the Disclosures that can be parsed
Anonymous readonly classes need PHP 8.3: the property is readonly
instead, as in SDJWTIssuerTest.
The OpenSSF Scorecard action only accepts the default branch, so every
push to the other maintained branches ended in a failed run. The
workflow is already disabled on GitHub; 5.0.x will lose the file with
the next merge-up.
SD-JWT: refuse at issuance the SD-JWTs the Holder and the Verifier reject
…ugh a setter

#712 gave GeneratorCommand a constructor taking the key factory as its
second argument, and kept the factory in a protected readonly property.
4.2 has neither, and both reach the commands an application extends:

- a subclass that declares its own non-readonly $jwkFactory property,
  private or not, typed or not, no longer loads: PHP refuses to redeclare
  a readonly property;
- the second argument of the constructor takes the place of the one that
  recent versions of the Symfony command accept for an invokable command
  ($code): passing one raises a TypeError.

The factory is now held in a private property, set by setJwkFactory()
and read through getJwkFactory(), which falls back to a default factory
so that the commands stay usable outside of a container. The constructor
is the one inherited from the Symfony command again. The bundle calls the
setter on every generator command it registers, the ML-DSA ones included.

Follow-up to #712
Disclosure::fromString() and SDJWT::fromString() reported every
Disclosure that the BoundedJsonDecoder rejected as "not valid JSON", and
SDJWT::fromString() and SDJWT::create() reported every JWS JSON
serialization it rejected as "must be a JSON object", even when the JSON
was valid but held more than 4096 values or was nested too deeply. As
the Disclosures of an SD-JWT share the budget, the Disclosure blamed was
the one on which the budget ran out, however small.

BoundedJsonDecoder::hasExceededMaxValues() tells whether the budget was
exceeded. A Disclosure or a JWS JSON serialization rejected for its
values or for its depth now says so, and an SD-JWT whose Disclosures go
beyond the budget is rejected as a whole. The exception classes and
codes are unchanged, and invalid JSON keeps its message.
…setter

fix(console): inject the key factory into the generator commands through a setter
fix(sd-jwt): tell the decoding bounds apart from invalid JSON
Disclosure::forObjectProperty() and Disclosure::forArrayElement() gave
one message for both bounds of the decoder when the Disclosure of a
value could not be parsed: "The value is nested too deeply or holds too
many JSON values". BoundedJsonDecoder::hasExceededMaxValues() now tells
whether the budget of 4096 values was exceeded; otherwise, since
json_encode() wrote the JSON, json_decode() rejected it for its depth.
Each bound has its own message. The exception class and code are
unchanged.
…laims

SDJWTIssuer::issueJson() checks its SD-JWT on a placeholder that the
Holder and the Verifier would parse. SDJWT::create() rejected the
placeholder with an InvalidSerializationException when an unprotected
header was nested too deeply, held more than 4096 JSON values or was a
list, and that exception escaped, while the Issuer refuses everything
else with an InvalidArgumentException. Near the bound, an unprotected
header of 4090 values was refused with a message that blamed the
Disclosures, even without any.

The JSON of the placeholder is now decoded first, as the Holder and the
Verifier decode it, and every failure to parse it is refused with an
InvalidArgumentException. In the JWS JSON serialization, the budget
message names the unprotected headers with the Disclosures.
…messages

fix(sd-jwt): name the bound a Disclosure factory hits
fix(sd-jwt): refuse the unparsable unprotected headers as the other claims
The JWS and JWE serializers rejected every token whose JSON the
BoundedJsonDecoder refused with "Unsupported input": invalid JSON, more
than 4096 values, or a document nested too deeply. The decoder now
names the bound, with "The JSON documents of the token hold more JSON
values than the 4096 that are decoded." or "A JSON document of the token
is nested too deeply.", and BoundedJsonDecoder::hasExceededMaxDepth()
tells the second case apart.

The JSON serializers let the exception of the decoder through, as
before. The compact serializers now keep its message for these two
bounds. Invalid JSON keeps "Unsupported input", and the exception
classes and codes are unchanged.
…messages

fix(serializers): name the bound a token goes beyond when it is decoded
…er managers

When no serializer could convert a token, JWSSerializerManager and
JWESerializerManager chained the exception of the last serializer they
tried. Only the serializer of the format of the token decodes it far
enough to reach a bound of the JSON decoder, so the reason was lost
whenever another serializer came after that one. A compact token was
then rejected as invalid JSON by a JSON serializer, and a flattened
token whose protected header went beyond a bound was rejected by the
general serializer for its missing members.

The decoder now throws a JsonBoundExceededException, a subclass of
InvalidArgumentException, for its two bounds. The managers chain the
last exception that goes back to one, and the exception of the last
serializer otherwise. Their own exception is unchanged.
…ound-reason

fix(serializers): chain the bound a token goes beyond in the serializer managers
When no serializer could convert a token, the managers chained the
exception of a bound or, without one, that of the last serializer they
tried. A token rejected by the serializer of its format for another
reason was then reported with the exception of a serializer of another
format, which had only rejected the token as foreign. A compact token
whose protected header is not a JSON object was reported as invalid
JSON by the general serializer.

A serializer now rejects an input of another serialization with an
UnrecognizedSerializationException, a subclass of
InvalidSerializationException. That is a compact serialization of
another number of parts or whose protected header part is not base64url,
or a JSON document that is not valid JSON, not an object, or without
the members of the serialization. The managers chain the exception of a
bound first, then the last exception without that mark, and the
exception of the last serializer otherwise. Messages and codes are
unchanged.
…ormat-reason

fix(serializers): chain the reason of the serializer a token belongs to
JsonConverter::decode() counted no value: a document of a few megabytes
full of colliding member names costs seconds of CPU, as for the tokens
before GHSA-2xq2. It decodes the key sets that JKUFactory and
X5UFactory fetch from a URL, without any limit on their size. Its
message was "Unsupported input." whatever the error. JWK::createFromJson(),
JWKSet::createFromJson() and JWKFactory::fromJsonObject() called
json_decode() directly, without bound either, and their JsonException
recorded the JSON of the key among the arguments of its trace.

These four methods now read a second argument, with func_get_arg(1)
until 5.0.0 declares it: true decodes a document of any number of
values, false refuses one of more than 4096 with a
JsonBoundExceededException, and without it, or with null, such a
document is decoded with a deprecation, as 5.0.0 refuses it by default.
JKUFactory and X5UFactory read the same policy as a third constructor
argument, and the bundle gets a "jose.jku_factory.allow_large_key_sets"
option.

JsonConverter::decode() names the error of json_decode(), and refuses a
document nested too deeply with a JsonBoundExceededException; the codes
and the chained JsonException are kept. The three key factories keep
their JsonException, thrown again as a copy without the key in its
trace. The tokens keep "Unsupported input.".

The console commands and the environment variable processor decode the
operator's own documents without bound. The SD-JWT Verifier bounds the
payload of the Key Binding JWT, signed by the Holder; that of the
Issuer-signed JWT, signed by the Issuer and holding a digest for each
Disclosure, is decoded without bound.
…xperimental packages

The bundle and the experimental packages of 4.3 use classes of the
library that 4.2 does not have: 29 for the bundle, 7 for the
experimental package. Both still required web-token/jwt-library ^4.0,
so updating web-token/jwt-bundle alone, without its dependencies, kept
the library 4.2. The container then failed to compile because the
Ed25519 class was missing, and the experimental ES256K could not be
loaded because its parent class was missing.

Both packages now require ^4.3. The other combinations keep working:
the bundle 4.2 and the experimental package 4.2 with the library 4.3,
and the bundle 4.3 with the experimental package 4.2.
…y again

In 4.2, JKUFactory and X5UFactory extended UrlKeySetFactory. Since #710
they only used the trait that holds the fetching code, so in 4.3 they
were no longer instances of that class: an instanceof check returned
false, and a parameter typed against UrlKeySetFactory refused them with
a TypeError. The backward compatibility promise only allows a new
parent class when the former one remains an ancestor.

Both classes extend UrlKeySetFactory again and still use the trait.
They keep their own constructor, so the deprecated constructor of
UrlKeySetFactory never runs: neither the two factories nor the classes
of an application that extend them trigger a deprecation, including
under Symfony's DebugClassLoader. A class that extends UrlKeySetFactory
directly still does. In 5.0.0, UrlKeySetFactory is removed and the two
factories no longer extend it.
…classes, deprecated

Up to 4.2, the bundle registered the "none" and "RSA1_5" algorithms
under the ids of their library classes,
Jose\Component\Signature\Algorithm\None and
Jose\Component\Encryption\Algorithm\KeyEncryption\RSA15. Since the two
algorithms moved to the jwt-unsecured and jwt-rsa15 packages, the
bundle registered the classes of those packages instead and the former
ids no longer existed: an application service that referenced one of
them, or autowired the library class, failed to compile.

The former ids are registered again as deprecated services without the
"jose.algorithm" tag, like the experimental ES256K: the "none" and
"RSA1_5" aliases are still served by the classes of the new packages.
Using one of them triggers the deprecation of the service, then that of
the class. Both are removed in 5.0.0, with the library classes.
…15-service-ids

fix(bundle): keep the service ids of the library "none" and "RSA1_5" classes, deprecated
…rl-key-set-factory

fix(key-management): JKUFactory and X5UFactory extend UrlKeySetFactory again
…rary-4-3

fix(composer): require web-token/jwt-library ^4.3 in the bundle and experimental packages
fix(json): bound the JSON documents decoded outside of a token
…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.
Spomky and others added 28 commits November 10, 2026 17:22
RsaAnalyzer converted "n" and "e" into big integers. The analyzed keys may
come from a third party and nothing bounds their length: without GMP, a
modulus of 2048 octets cost 0.57 s with BCMath and 109 s in pure PHP, and
32 KiB cost 155 s with BCMath.

The bit length of the modulus is now read from its octets, leading zero
octets ignored, as RSAKey does. The exponent is converted only when it fits
in three octets: a longer value is at least 2^24.

The verdicts are those of the previous commit. The new tests cover the
bounds: 2047 and 2048-bit moduli, exponents with leading zero octets or
longer than four octets.
ESKeyAnalyzer reported coordinates of the wrong size, then converted them
into big integers anyway. Without GMP, coordinates of 1 KiB cost 27.5 s in
pure PHP and 8 KiB cost 2 s with BCMath. The analysis now stops after the
size message, as it does for empty coordinates, and the curve is created
once.
"Resolves issue #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. #824 targeted the default branch with that line and
was never linked to #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.
ci(github): use a closing keyword in the pull request template
…ding

fix(key-mgmt): analyze RSA n and e and EC coordinates by their integer value
RSAKey bounded the public exponent "e" to 64 bits above a modulus of 3072
bits only, as OpenSSL does, and to the length of the modulus below it. A
key of 3072 bits whose exponent was as long as its modulus was therefore
accepted, and the public operation PS*, RSA-OAEP and RSA1_5 compute in PHP
costs as many squarings as "e" has bits: with GMP, a PS256 signature under
such a key, which the sender of a DPoP proof chooses, took 30.9 ms to
reject, against 0.7 ms with a 64-bit exponent; with BCMath, 1.48 s against
52 ms.

The exponent is now refused beyond 64 bits whatever the modulus, and
beyond the length of the modulus as before. The dearest key left is one
of 16384 bits with a 64-bit exponent: 8.6 ms with GMP, 1.18 s with BCMath,
as before this change. A key with a larger exponent is refused although
FIPS 186-5 allows exponents below 2^256: generators draw 65537, and Go and
BoringSSL already refuse exponents above 2^31 - 1 and 33 bits.
…ports on 4.2.x

The phpqa image rebuilt on 2026-11-20 ships PHPStan 2.3.7, which reports a
mixed value as the condition of the ternaries of the processHeaders()
methods of JSONFlattenedSerializer and JSONGeneralSerializer and of the if
of MixedPublicAndPrivateKeys: the Static Analysis job failed on 4.2.x
whatever the change. The baseline, generated by castor phpstan-baseline,
gains those three entries and nothing else.
fix(core): bound the RSA public exponent to 64 bits whatever the modulus
PS256, PS384 and PS512 verification and RSA-OAEP, RSA-OAEP-256 and
RSA1_5 encryption raised the signature or the encoded message to the
public exponent with brick/math. Without GMP, that costs seconds even
with ordinary keys, whoever provides them: in pure PHP, a PS256
verification took 3 s with an RSA-2048 key and 15 s with an RSA-4096
key, and with BCMath a 3072-bit key whose exponent is as long as the
modulus took 0.9 s.

RSAKey::applyPublicKey() now computes input^e mod n with OpenSSL
(OPENSSL_NO_PADDING) when the extension is loaded, and with brick/math
otherwise. OpenSSL applies its own limits to the key, and the cost no
longer depends on the calculator: about 0.2 ms per operation with an
RSA-2048 key, with GMP, with BCMath or with neither. The public key is
handed to OpenSSL as a PEM, which is now written without
pki-framework, whose DER lengths go through brick/math: toPEM() for a
public key drops from 0.23 ms to 0.03 ms, which RS256, RS384 and RS512
benefit from as well, and the PEM is the same byte for byte. With GMP,
a PS256 verification with an RSA-2048 key takes 0.19 ms, against
0.11 ms before.

Private key operations are unchanged. An input as large as the
modulus, or a key that OpenSSL refuses (a public exponent as long as
the modulus but larger), now raises a RuntimeException.

Reported by Anthropic's OSS Scanner (ANT-2026-9EHC9J38 and ANT-2026-WD2XF3WZ).

(cherry picked from commit 9323191)
RSA-OAEP, RSA-OAEP-256 and RSA1_5 decryption raised the encrypted key to
the private exponent with brick/math. The sender of a token chooses that
encrypted key, and the key it is encrypted to is public, so anyone could
make an application pay for a private key operation with each token:
with an RSA-2048 key, about 130 s in pure PHP and 0.12 s with BCMath,
against 3 ms with GMP.

RSAKey::applyPrivateKey() now computes input^d mod n with OpenSSL
(OPENSSL_NO_PADDING) when the extension is loaded, and with brick/math
otherwise. The key is handed to OpenSSL by its members through
openssl_pkey_new(), so a key without its CRT members works as before,
and OpenSSL blinds the operation. A forged token now costs about 2 ms
with any calculator. The padding checks stay in PHP and are unchanged.

An input as large as the modulus still raises a RuntimeException, now
with a message.
PS256, PS384 and PS512 signing applied the private key with brick/math:
with an RSA-2048 key, about 125 s per signature in pure PHP and 0.15 s
with BCMath. It now goes through RSAKey::applyPrivateKey(), like RSA-OAEP
and RSA1_5 decryption, and costs a few milliseconds with any calculator.
The signatures are the same: only the RSA primitive moves to OpenSSL.
…tever the change

The Static Analysis job fails on 4.3.x for reasons outside the code:

- PHPStan 2.3.7, shipped by the phpqa image since its rebuild of
  2026-11-20, reports a mixed value as the condition of the ternaries of
  the processHeaders() methods of JSONFlattenedSerializer and
  JSONGeneralSerializer and of the if of MixedPublicAndPrivateKeys, as on
  4.2.x (4029d7e);
- symfony/dependency-injection 8.2.0 declares the $config argument of
  ContainerBuilder::prependExtensionConfig() as array<string, mixed>,
  while ConfigurationHelper::updateJoseConfiguration() passes an
  array<mixed>.

The baseline, generated by castor phpstan-baseline with the current
image, gains those four entries and nothing else.
ci: add to the PHPStan baseline the four errors reported on 4.3.x whatever the change
…apping it

A128GCMKW, A192GCMKW and A256GCMKW hand the whole encrypted key to
openssl_decrypt(), which decrypts it before checking the authentication
tag, for every key of the key set. The size check added for the AES Key
Wrap algorithms skipped them, so a token with an encrypted key of any
size was rejected only after work and memory proportional to that size.

AES-GCM key wrapping returns as many bytes as it wraps, its tag being the
"tag" header parameter: JWEDecrypter now compares the size of the
encrypted key with the CEK size before calling these algorithms. The
tokens it rejects are the ones it already rejected, either because the
tag did not match or because the unwrapped key had the wrong size: only
the failure passed to the callable of decrypt() and chained by the
loaders changes.

Reported by inanna-malick, as a follow-up of ANT-2026-GFP863VS.
… the PBES2 cap

JWEDecrypter tries the keys of a key set one after the other and derives
each password with the iteration count of the token. The PBES2 cap bounds
one derivation, and since the recipients of a token share it, one
recipient tried with one key: a recipient at the cap tried with a key set
holding N passwords costs N derivations at the cap.

Deriving more iterations in total than the share of a recipient with the
keys of a key set is now deprecated. From 5.0.0, the passwords tried for a
recipient share that part of the cap, and the ones beyond it are not
tried. Only the keys that are derived count: keys of another type, and
keys rejected for their usage or their algorithm, are left out, so a key
set holding one password next to other keys keeps the whole share.
Nothing is rejected: the tokens decrypted before are still decrypted.

Reported by inanna-malick, as a follow-up of ANT-2026-P0RDGIIJ.
fix(encryption): check the size of an AES-GCM wrapped key before unwrapping it
fix(encryption): deprecate deriving the passwords of a key set beyond the PBES2 cap
* commit 'd5787015':
  Sign with RSA-PSS through OpenSSL
  Compute the RSA private operation with OpenSSL
  Compute the RSA public operation with OpenSSL
…n 8.2 reports on 4.2.x

symfony/dependency-injection 8.2.0 declares the $config argument of
ContainerBuilder::prependExtensionConfig() as array<string, mixed>,
while ConfigurationHelper::updateJoseConfiguration() passes an
array<mixed>. The Static Analysis job therefore fails on 4.2.x whatever
the change, and the tests it gates are skipped. 4.3.x got the same entry
in #832.

The baseline, generated by castor phpstan-baseline with the current
image, gains that entry and nothing else.
Brings 4.2.8 (#825, #828) and 4.2.9 into 4.3.x. Conflicts resolved:

- RSAKey: the 4.2.x code (exponent bounded to 64 bits whatever the
  modulus, applyPrivateKey() and its OpenSSL members) with the Jose
  InvalidKeyException and RuntimeException of 4.3.x;
- RSACrypt and Signature\Algorithm\Util\RSA: the 4.3.x imports without
  BigInteger, and the private helpers removed as on 4.2.x;
- RsaAnalyzer: the 4.2.x version, which no longer needs
  InvalidKeyException;
- RSAKeyTest: the 4.3.x imports plus array_flip and array_intersect_key,
  and the new tests;
- JWKAnalyzerTest: (new JWKFactory())->ec() instead of the deprecated
  JWKFactory::createECKey().
OpenSSL loads an Ed25519 public key whose point is of small order, and with
the neutral point as key it verifies the signature R = the neutral point,
S = 0 for any input. Without ext-sodium, AbstractEdDSA::verify() goes through
OKPKey::verifyWithOpenSSL(), so Ed25519 and EdDSA accepted such a forged
signature. With sodium, sodium_crypto_sign_verify_detached() refuses it.

OKPKey::isSmallOrderEd25519Point() compares "x", sign bit cleared, with the 7
encodings libsodium refuses (ge25519_has_small_order()): the 8 points of order
1, 2, 4 and 8 and the non-canonical encodings of y = 0 and y = 1. It needs no
extension. verifyWithOpenSSL() returns false for such a key, and
OKPKeyAnalyzer reports it whichever backend is loaded.
OKPKeyAnalyzer only checked the size of "x" and the points of small order, so
an Ed25519 key whose "x" decodes to no point of the curve raised no message,
while every signature verification with it fails.

OKPKey::isValidEd25519PublicKey() uses sodium when it is loaded:
sodium_crypto_sign_ed25519_pk_to_curve25519() also requires the point to be in
the prime-order subgroup. Without sodium, OKPKey::isEd25519Point() decodes
"x" as RFC 8032 section 5.1.3 does, with brick/math: y lower than p and
(y^2 - 1) / (d y^2 + 1) a square modulo p. A point outside the prime-order
subgroup is then only reported with sodium.

The tests build the "x" of a well-formed Ed25519 key from the RFC 8037 key, as
random bytes are a point of the curve only half of the time.
OpenSSL accepts a forged Ed448 signature for a public key of order 4: with
"x" the encoding of y = 0 (x = 1 or -1), the signature R = that point, S = 0
verifies for any input, on OpenSSL 3.5 and 4.1. Ed448 has no sodium backend,
so the Ed448 algorithm accepted it whatever the extensions loaded.

OKPKey::isSmallOrderEd448Point() compares "x", sign bit cleared, with the
encodings of y = 0, 1 and p - 1 and the non-canonical encodings of y = 0 and
y = 1. verifyWithOpenSSL() returns false for such a key, and OKPKeyAnalyzer
reports it.
isEd25519Point() inverted v by Fermat and then raised u / v to (p - 1) / 2:
two modPow on 255-bit numbers, 8.4 s with the native calculator of
brick/math. As v = d y^2 + 1 is never zero, u / v is a square exactly when
u * v is one: the inversion goes away and the call takes half the time.

isValidEd25519PublicKey() checks the points of small order before decoding
"x", and its docblock says that the prime-order subgroup is only checked with
sodium. The comment of the test helper moves to its docblock.
* complete/pr-827:
  fix(okp): decode an Ed25519 point with a single exponentiation

# Conflicts:
#	src/Library/Core/Util/OKPKey.php
fix(okp): refuse the Ed25519 public keys of small order and report the invalid ones
fix(okp): refuse the Ed448 public keys of small order
@Spomky
Spomky merged commit cd6ef98 into 5.0.x Nov 29, 2026
29 of 31 checks passed
@Spomky
Spomky deleted the 4.3.x-merge-up-into-5.0.x_zUT9LIP0 branch November 29, 2026 19:13
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.

2 participants