8000 Voter priority in reverse order from lowest to highest · Issue #21660 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Voter priority in reverse order from lowest to highest #21660
Closed
@scoolen

Description

@scoolen
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version v2.8.11

Although this is poorly documented, I understand that voter services can have a priority.

Relevant commit: 0643dc4

Similar to other DI tags with a priority attribute this was intended to be implemented as follows:

The priority value is optional and defaults to 0. The higher the priority, the sooner it gets executed.

The compiler pass responsible for adding all configured voters is the AddSecurityVoterPass which uses an SplPriorityQueue (max heap) to correctly order the voters one by one.

The priority queue is then converted to an array and passed to the AccessDecissionManager service definition by adding a method call for setVoters.

The problem is that right after the array conversion a ksort is done on the voters array. This actually reverses the prioritization done by SplPriorityQueue!

Result: voters are ordered from lowest to highest priority and are also processed in this order in the different decision strategies.

I think the priority queue was added later as an optimization for setting the prio as the indices of an associative array, but the obsolete call to ksort was never removed.

I double checked other compiler passes using priority attributes:

Compiler Pass A-OK unit tested impl
AddCacheWarmerPass yes yes set + ksort
AddSecurityVotersPass no no prio queue + ksort
ConfigCachePass yes yes set + ksort
ProfilerPass yes no prio queue
PropertyInfoPass yes yes set + ksort
SerializerPass yes yes set + ksort

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0