Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Dec 7, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

In #62329, we assume that the response of Definition::getTags() has the type array<string, list<array>>. However, when using Definition::setTags(), we can set any array value without validation.

In symfony/monolog-bundle#485, the tag attributes are filtered, which generates gaps in the keys. The PR mentioned above causes MonologBundle to fail. This can be fixed by symfony/monolog-bundle#563. However I believe the issue should also be addressed in Symfony.

This PR targets 7.3 because the bug is in this version, but the patch can be applied in 6.4. Switched to 6.4

@carsonbot carsonbot added this to the 7.3 milestone Dec 7, 2025
@carsonbot carsonbot changed the title [DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag [DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag Dec 7, 2025
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 6.4? I think this was mostly undefined, but indeed it's better to define the behavior.

@GromNaN
Copy link
Member Author

GromNaN commented Dec 7, 2025

We can also fix the bug directly where it was introduced:

diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
index 00fdaaf2b47..751f8a535c8 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
@@ -81,6 +81,7 @@ trait PriorityTaggedServiceTrait
                 $phpAttributes = [];
             }
 
+            $attributes = array_values($attributes);
             for ($i = 0; $i < \count($attributes); ++$i) {
                 if (!($attribute = $attributes[$i]) && $phpAttributes) {
                     array_splice($attributes, $i--, 1, $phpAttributes);

@GromNaN GromNaN changed the base branch from 7.3 to 6.4 December 7, 2025 20:48
@GromNaN GromNaN modified the milestones: 7.3, 6.4 Dec 7, 2025
@OskarStark OskarStark changed the title [DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag [DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag Dec 7, 2025
;
$container->register(ControllerArguments::class, ControllerArguments::class)
->setTags(['controller.service_arguments'])
->setTags(['controller.service_arguments' => []])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me to be a breaking change if people inject random values via
Definition::setTags() and expect to retrieve these values with Definition::getTags().

@GromNaN
Copy link
Member Author

GromNaN commented Dec 7, 2025

Replaced by #62685

We can improve the type of Definition::getTags() and Definition::setTags() in 8.1.

nicolas-grekas added a commit that referenced this pull request Dec 8, 2025
…n tag attributes are not a list (GromNaN)

This PR was merged into the 7.3 branch.

Discussion
----------

[DependencyInjection] Fix `PriorityTaggedServiceTrait` when tag attributes are not a list

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Alternative to #62683

Ensure the attributes of the tag are in a list before iterating on them using sequential indexes.

> In symfony/monolog-bundle#485, the tag attributes are filtered, which generates gaps in the keys. The PR mentioned above causes MonologBundle to fail. This can be fixed by symfony/monolog-bundle#563. However I believe the issue should also be addressed in Symfony.

Commits
-------

5a4a036 [DependencyInjection] Fix PriorityTaggedServiceTrait when tag attributes are not a list
@GromNaN GromNaN deleted the tags-list branch December 8, 2025 07:11
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.

3 participants