Repository navigation
fix(bundle): deprecate tagging two services with the same alias - #784
Merged
Merged
Conversation
The algorithm, header checker and claim checker compiler passes add every
tagged service to its factory under the alias of its tag. The factory keeps
one service per alias, so when two services share an alias, the one tagged
last replaces the other without a word. The application's services are
defined before the bundle's: a service of the application tagged with an
alias the bundle already uses ("exp", "iat", "nbf" or an algorithm name) is
replaced by the bundle's own service, and a header checker meant to accept
protected headers only can be silently swapped for one that does not.
The three passes now trigger a deprecation naming both services when an
alias is shared, and keep the current resolution. One service tagged twice
with the same alias stays silent. Sharing an alias will throw an exception
in 5.0.0. The passes share that code through an internal trait, which also
drops three PHPStan baseline entries.
Reported by Anthropic's OSS Scanner (ANT-2026-635NQ9DS).
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.
Fixes #769.
The defect
AlgorithmCompilerPass,HeaderCheckerCompilerPassandClaimCheckerCompilerPassadd every tagged service to their factory withadd($alias, $service). The factory keeps one service per alias, and the passes never checked whether an alias was already taken. The service tagged last replaces the other, and the container compiles without a word.The application's services are defined before the bundle's. So an application service tagged with an alias that the bundle already uses (
exp,iat,nbf, or an algorithm name) is replaced by the bundle's own service. With the configuration of the issue:jose.header_checker.apiholds the bundle'sExpirationTimeChecker, whoseprotectedHeaderOnly()isfalse. A JWS in a JSON serialization that carriesexponly in its unprotected header passescheck($jws, 0, ['exp']). I reproduced it with a real kernel on4.3.x. Under the aliasexp, the token is accepted. Underexp_protected, the application's checker is used and the token is refused (The header parameter "exp" must be protected.). Algorithms behave the same way: an algorithm service built with other constructor arguments and tagged with its standard name is replaced by the bundle's default instance.The fix
As proposed in the issue, for 4.3.0:
debug:container --deprecationsand the profiler show (checked with a debug kernel).@internaltrait,TaggedServiceAliases. It reads the tag attributes with their types, which removes three entries from the PHPStan baseline and adds none.The 5.0.0 part, an exception instead of the deprecation, is #786 (draft, on
5.0.x).This is 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, as #756 did with #778.
This is the companion of #778 (#756), which covers two checkers of the same claim or header parameter inside one manager. The two PRs touch different files.
Behaviour change
No public or protected signature changes.
Tests
tests/Bundle/JoseFramework/DependencyInjection/Compiler/TaggedServiceAliasesTest.phpruns each of the three passes on a bareContainerBuilder:tests/Bundle/JoseFramework/Functional/AliasCollisionTest.phpuses a real kernel:jose.header_checker.apistill holds the bundle's checker;typ:option.tests/Bundle/JoseFramework/IsolatedKernel.phpis a kernel configured by a closure and compiled in a directory of its own. A deprecation triggered during compilation only shows when the container is actually compiled, and the shared cache ofAppKernelskips compilation once it is warm.Verification
--prefer-lowest(Symfony 7.0): 2,270 tests, 113 skipped and 2 incomplete.phpqa:8.4image.src/(443 on the base, 444 here) differs only by the new@internaltrait.process()and every other public or protected signature are unchanged.PBES2-HS256+A128KWbuilt with other arguments). Two more add a bundle registered after JoseFrameworkBundle that redefinesexp, alone and together with the application's service. The rest cover a tag without an alias, anullalias, one service tagged twice, one service under two aliases, integer and empty aliases, the bundle alone, and the full test configuration ofAppKernel. The factories, the managers, the outcome of the boot and the exception messages are identical. The only difference is the new notice, in the 6 scenarios where two services share an alias.add(string $alias, …)call of the generated container coerces, keeps its current behaviour, without a notice.trigger_deprecation(), after clearingvar/cache. The new notice is triggered 4 times, all by the new tests. No existing test or configuration triggers it, including the configuration of the test kernel.trigger_deprecation()comes fromweb-token/jwt-libraryandsymfony/dependency-injection, which the bundle already requires.5.0.xwithout conflict.Found by the Anthropic OSS Scanner (ANT-2026-635NQ9DS).