Security: Skip unregistered roles in ResourceAclHelper instead of crashing#8735
Open
addow wants to merge 1 commit into
Open
Security: Skip unregistered roles in ResourceAclHelper instead of crashing#8735addow wants to merge 1 commit into
addow wants to merge 1 commit into
Conversation
…shing
ResourceAclHelper::isAllowed() iterates every role in $user->getRoles()
and calls Acl::isAllowed($role, ...) for each, but the Laminas ACL
registry (built in init()) only ever registers a small fixed set of
resource-permission roles (ROLE_USER, ROLE_STUDENT,
ROLE_CURRENT_COURSE_TEACHER, ...).
Any other role the user happens to carry - e.g. ROLE_SESSION_MANAGER,
ROLE_PREVIOUS_ADMIN or ROLE_ALLOWED_TO_SWITCH, all present on an
admin's token while using "Login as" - makes Laminas throw
Acl\Exception\InvalidArgumentException("Role '...' not found"),
crashing the whole request with a 500 instead of just being irrelevant
to the resource-level permission check.
This affects any AbstractResource-backed resource (documents, forums,
etc.) whenever the current user's Symfony role set contains a role the
ACL never registered - most commonly while impersonating another user
via "Login as".
Fix: skip roles the ACL hasn't registered via Acl::hasRole() instead
of asking it about them.
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.
Summary
ResourceAclHelper::isAllowed()iterates every role in$user->getRoles()and callsAcl::isAllowed($role, ...)for each, but the Laminas ACL registry (built ininit()) only ever registers a small fixed set of resource-permission roles (ROLE_USER,ROLE_STUDENT,ROLE_CURRENT_COURSE_TEACHER, ...).ROLE_SESSION_MANAGER,ROLE_PREVIOUS_ADMINorROLE_ALLOWED_TO_SWITCH, all present on an admin's token while using "Login as" - makes Laminas throwAcl\Exception\InvalidArgumentException("Role '...' not found"), crashing the whole request with a 500 instead of just being irrelevant to the resource-level permission check.AbstractResource-backed resource (documents, forums, etc.) whenever the current user's Symfony role set contains a role the ACL never registered - most commonly while impersonating another user via "Login as".Acl::hasRole()instead of asking it about them.Test plan
tests/CoreBundle/Helpers/ResourceAclHelperTest.php, reproducing the crash with a mocked user carryingROLE_SESSION_MANAGER/ROLE_PREVIOUS_ADMIN/ROLE_ALLOWED_TO_SWITCH- fails before the fix, passes after.vendor/bin/phpstan analyseclean on the changed file (pre-existing unrelated findings on lines untouched by this change were verified present before this diff too).