Skip to content

fix(checker): deprecate a second checker of the same claim or header parameter - #778

Merged
Spomky merged 2 commits into
4.3.xfrom
fix/checker-manager-duplicate-checkers
Nov 8, 2026
Merged

Spomky merged 2 commits into
4.3.xfrom
fix/checker-manager-duplicate-checkers

Conversation

@Spomky

@Spomky Spomky commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #756.

The defect

ClaimCheckerManager and HeaderCheckerManager index their checkers by supportedClaim() / supportedHeader(). When two checkers of the list cover the same name, the second replaces the first, which never runs, and nothing is thrown or logged:

$manager = new ClaimCheckerManager([
    new ExpirationTimeChecker($clock),
    new CallableChecker('exp', $maxLifetime), // at most one hour left to live
]);
$manager->check(['exp' => time() - 10]); // passes: the ExpirationTimeChecker is gone

In the other order, a token valid for ten years passes, so no order enforces both rules. In a header checker manager, the replacement can also drop the protected-only requirement: AudienceChecker('api', true) followed by AudienceChecker('api') accepts an unprotected aud.

All the construction paths end in these two constructors: the factories of the library and of the bundle, jose.checkers.claims / jose.checkers.headers, the header_checkers of the loaders, and the typ: option, whose generated TypeChecker replaces any typ checker listed in headers: of the same manager.

The fix

As proposed in the issue, for 4.3.0:

  • Both constructors trigger a deprecation when a name is already covered by a different checker instance. The message names the claim or header parameter and the classes of the two checkers, because the bundle lists hold aliases that do not show the name:

    Since web-token/jwt-library 4.3.0: Building a claim checker manager with more than one checker of the claim "exp" is deprecated and will not be possible in 5.0.0: only the last one is kept, so "Jose\Component\Checker\CallableChecker" replaces "Jose\Component\Checker\ExpirationTimeChecker", which never runs. Combine the rules of a claim in a single checker.

  • The behaviour does not change: the last checker is still the one kept.
  • The same instance listed twice stays silent. The alias registry allows one checker under several aliases, and listing two of them loses no rule.
  • The class docblocks say that a manager holds one checker per claim or header parameter, and that the rules of a claim belong in a single checker.

The 5.0.0 part, an InvalidArgumentException instead of the deprecation, is #783 on 5.0.x.

Not in 4.2.7: the fix is a deprecation, and the patch branches take none. The issue moves to the 4.3.0 milestone with this PR.

Behaviour change

checkers given to the manager before after
one per claim or header parameter — unchanged, no notice
the same instance twice (e.g. two aliases of one service) kept once unchanged, no notice
two different checkers of one claim or header parameter the last one kept, silently the last one kept, one notice per replaced checker

No public or protected signature changes.

Tests

  • ClaimCheckerManagerTest and the new HeaderCheckerManagerTest: the notice for two audiences, for exp followed by a CallableChecker on exp, for two TypeCheckers, and for a protected aud checker replaced by an unprotected one; the behaviour kept (the replaced checker still never runs, with exactly one notice); the same instance listed twice stays silent.
  • Bundle, functional: the configuration of the issue, claims: ['exp', 'iat', 'nbf', 'max_lifetime'] with max_lifetime a CallableChecker('exp', …) service, and a typ checker listed in headers: next to the typ: option. Both managers are new entries of config_test.yml; the checker is a new service of the test bundle.
  • The two smoke tests that built a manager from all the aliases of the bundle factories now leave out the aliases that cover a name twice. The header one already combined three generated typ.* checkers.

Verification

  • On the base branch, the 8 new tests that expect the notice fail (no notice) and the others pass. The assertions inside them already show the defect there: the bundle's exp_twice manager holds the CallableChecker and no ExpirationTimeChecker. With the fix, the 106 tests of tests/Component/Checker and tests/Bundle/JoseFramework/Functional/Checker pass.
  • Full suite on PHP 8.5: 2,270 tests green (base: 2,256, with the same 4 skipped and 2 incomplete). A run with a logging trigger_deprecation() shows that only the new tests trigger the notice.
  • ECS, Rector, PHPStan and Deptrac are clean with the current phpqa:8.4 image.
  • BC: the public and protected API of src/, dumped by reflection, is identical to the base. A probe over 13 cases (both managers, both library factories, the two deprecated bundle subclasses, a generator, one checker under two aliases) returns the same results on the base and on the branch. Only the notice count differs, and only where a checker is replaced.
  • No new dependency: trigger_deprecation() comes from symfony/deprecation-contracts, which web-token/jwt-library, the split that ships the managers, already requires (^2.5|^3.0). The lowest-deps job passes.
  • The bundle builds an alias list itself only for the typ: option. It triggers the notice only when the application also lists a typ checker in headers:. The managers of the test configuration that use typ: alone trigger nothing.
  • Neighbouring PRs: fix(bundle): deprecate tagging two services with the same alias #784 merges with this one without conflict. fix(bundle): stop merging the alias lists of a service by position #785 deduplicates the aliases of the lists it adds up, and its test lists cover distinct claims, so its merge-up into 4.3.x triggers no notice.
  • Mutation testing: the CI job generated 12 mutants on the diff, killed 6 and skipped 6 on its 3-second timeout (the bundle tests that cover them boot a kernel). Replayed locally with a 60-second timeout, all 12 are killed.
  • Merge-up: the commit merges into 5.0.x without conflict. The 5.0.0 part is fix(checker): reject a second checker of the same claim or header parameter #783 (draft).

Found by the Anthropic OSS Scanner (ANT-2026-YWJFJRRB).

…parameter

ClaimCheckerManager and HeaderCheckerManager index their checkers by
the name each one covers. When two checkers of the list cover the same
claim or header parameter, the second replaces the first, which never
runs, and nothing tells the application. With an ExpirationTimeChecker
followed by a CallableChecker on "exp", an expired token passes; in the
other order, a token valid for ten years passes. In a header checker
manager, the replacement can also drop the protected-only requirement
of the parameter.

All the construction paths end in these two constructors: the
factories of the library and of the bundle, the jose.checkers.claims
and jose.checkers.headers managers, the header_checkers of the loaders,
and the typ option, whose TypeChecker replaces any typ checker listed
in the headers of the same manager.

Building a manager with a second checker for a name already covered
now triggers a deprecation that names the claim or header parameter
and the classes of the two checkers. The last checker is still the one
kept. The same instance listed twice, for instance under two aliases,
stays silent. 5.0.0 will throw instead.

Two functional tests reproduce the bundle cases of the report: the
claims exp, iat, nbf and max_lifetime, where max_lifetime is a
CallableChecker on "exp", and a typ checker listed next to the typ
option.

Reported by Anthropic's OSS Scanner (ANT-2026-YWJFJRRB).

Fixes #756
* origin/4.3.x:
  Name both key orders for the sender key of decrypt()
  Throw the Jose exception from the loader factories
  fix(bundle): keep the key attribute of the alias lists
  fix(key-mgmt): keep the JKU/X5U requests whose headers cannot be serialized
  fix(encryption): accept the AES-CBC-HMAC tags of earlier versions until 5.0.0
  Only wrap the x5u entries that start with file://
  fix(bundle): deprecate tagging two services with the same alias
  fix(bundle): stop merging the alias lists of a service by position
  fix(encryption): AL of AES-CBC-HMAC is the length of the whole AAD
  fix(core): reject the bytes outside the alphabet on the sodium path
  Compute ECDH-SS from the two static keys only
  fix(key-mgmt): include the request headers in the key of the JKU/X5U cache
  fix: refuse header checkers that a loader factory cannot apply
  Keep an x5u entry from naming a local file
  fix(checker): accept a value only when the callable returns true

# Conflicts:
#	tests/Bundle/JoseFramework/TestBundle/Resources/config/services.php
@Spomky
Spomky merged commit 72191a5 into 4.3.x Nov 8, 2026
18 checks passed
@Spomky
Spomky deleted the fix/checker-manager-duplicate-checkers branch November 8, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claim and header checker managers silently keep only the last checker of a claim or header parameter

1 participant