Skip to content

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

Draft
Spomky wants to merge 4 commits into
5.0.xfrom
fix/checker-manager-duplicate-checkers-5.0.x
Draft

Spomky wants to merge 4 commits into
5.0.xfrom
fix/checker-manager-duplicate-checkers-5.0.x

Conversation

@Spomky

@Spomky Spomky commented Nov 8, 2026

Copy link
Copy Markdown
Member

Second part of #756, for 5.0.0. It depends on #778 (4.3.x): this branch merges the commit of #778, so that the merge-up of 4.3.x into 5.0.x stays free of conflicts. Draft until #778 is merged; if #778 changes during the review, this branch is rebuilt on top of it.

The change

With #778 (4.3.0), a claim or header checker manager given two different checkers of the same claim or header parameter triggers a deprecation and keeps the last one. In 5.0.0, both constructors throw an InvalidArgumentException instead:

The claim "exp" is given two checkers, "Jose\Component\Checker\ExpirationTimeChecker" and "Jose\Component\Checker\CallableChecker", but a claim checker manager takes a single checker per claim. Combine the rules of a claim in a single checker.

  • The same instance listed twice, for instance under two aliases of one service, is still accepted.
  • In the bundle, the exception is thrown when the manager service is built (jose.checkers.claims, jose.checkers.headers with or without typ:, the header_checkers of the loaders). An application with such a list fails on first use instead of running without one of its rules.
  • The tests that expected the notice now expect the exception. The two tests that checked the behaviour kept in 4.3 are removed.

This removes two of the trigger_deprecation() calls that the "Done when" grep of #717 has to bring to zero.

Verification

  • tests/Component/Checker and tests/Bundle/JoseFramework/Functional/Checker: 104 tests green. Full suite on PHP 8.5: 2,265 tests green, with the same 4 skipped and 2 incomplete as the base.
  • ECS, Rector, PHPStan and Deptrac are clean with the current phpqa:8.4 image.

For the migration guide

A claim or header checker manager takes one checker per claim or header parameter. A list that gives a claim two checkers triggered a deprecation in 4.3. In 5.0 it throws when the manager is built. Combine the rules in one checker, for instance a checker of your own that calls ExpirationTimeChecker::checkClaim() and then applies its own rule, or remove the redundant entry.

* fix/checker-manager-duplicate-checkers:
  fix(checker): deprecate a second checker of the same claim or header parameter
…ameter

Since 4.3.0, building a claim or header checker manager with two
different checkers of the same claim or header parameter triggers a
deprecation, and the second checker replaces the first, which never
runs. Both constructors now throw an InvalidArgumentException instead,
naming the claim or header parameter and the classes of the two
checkers. The same instance listed twice, for instance under two
aliases of one service, is still accepted.

In the bundle, the exception is thrown when the manager service is
built, so an application with such a list fails on first use instead
of running without one of its rules.

Refs #756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant