Skip to content

[zend-acl] fix rule removal for numeric ids and for all resources - #238

Open
falkenhawk wants to merge 2 commits into
masterfrom
fix-acl-remove-rules
Open

falkenhawk wants to merge 2 commits into
masterfrom
fix-acl-remove-rules

Conversation

@falkenhawk

@falkenhawk falkenhawk commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Removing roles, resources or rules from Zend_Acl can leave rules behind.

1) Removed roles and resources with numeric ids keep their rules

php stores array keys like '5' as integers.
removeRole() and remove() look for the rules of the removed role or resource with ===, comparing the string id '5' with the integer key 5.
That never matches, so the rules stay, and a role or resource added later with the same id gets them back:

$acl->addRole('5')->addResource('page')->allow('5', 'page');
$acl->removeRole('5');
$acl->addRole('5');
$acl->isAllowed('5', 'page'); // true, expected false

The same happens with remove('123') followed by addResource('123').
Both ids are now compared as strings.

2) removeAllow(null, null) leaves deny rules behind

removeAllow(null, null) should remove the allow rules of all roles on all resources.
Instead, it turns the rule for all roles on each single resource into a deny rule:

$acl->addRole('guest')->addResource('a')->allow(null, 'a');
$acl->removeAllow(null, null);
$acl->allow();                 // allow everything by default
$acl->isAllowed('guest', 'a'); // false, a deny rule was left on 'a'

Only the rule for all roles on all resources - the default rule - should be reset to deny. Every other rule should simply be removed.
The code for a null resource list was added for ZF-10649 and checks only the role (zendframework/zf1).
It also creates empty rule entries for every resource, which then raise Undefined array key "allPrivileges" warnings on php 8.
removeDeny(null, null) has the same problem.

That code now works like the code for a given list of resources right above it: it creates no rule entries, and it resets to deny only when both role and resource are null.
laminas-permissions-acl does the same.

Backwards compatibility

Only the wrong results shown above change.

Ported from a private repository, based on work by @marcing. removeRole() is fixed in addition.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant