fix: scope the formit permission to its own policy template#314
Open
Ibochkarev wants to merge 1 commit into
Open
fix: scope the formit permission to its own policy template#314Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
permissions.resolver.php created the "formit" and "formit_encryptions" modAccessPermission bits only on templates listed in each permission's `templates` key (AdministratorTemplate), which is correct. But the second loop, which writes the actual true/false value into every modAccessPolicy's `data` blob, never checked that `templates` restriction. Any permission without an explicit `policies` allowlist (formit) fell into the unconditional `$data[$permission['name']] = true` branch for every single policy in the system, including ones built from unrelated templates like ElementTemplate. Build a template id => name lookup while walking the templates, then skip a policy in the second loop whenever its template isn't in the permission's `templates` list, so the value is only written for policies that actually have that permission bit defined on their template. Reproduced both the bug and the fix with a standalone script stubbing xPDO's getCollection()/getObject()/newObject() against the resolver's actual logic: before the fix, a policy on an unrelated template picked up `formit => true`; after the fix, that key is never added. See Sterc#246 for the broader question of whether FormIt should own its own policy template instead of piggybacking on AdministratorTemplate. This just stops the current approach from leaking into policies it has no business touching. Fixes Sterc#272
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.
permissions.resolver.phpcreates theformitandformit_encryptionsmodAccessPermissionbits only on templates listed in each permission'stemplateskey (AdministratorTemplate), which is correct.The second loop, which writes the actual true/false value into every
modAccessPolicy'sdatablob, never checked that sametemplatesrestriction. Any permission without an explicitpoliciesallowlist (formit) fell into the unconditional$data[$permission['name']] = truebranch for every policy in the system, including ones built from unrelated templates likeElementTemplate. That's the "10 of 9 active policies" the issue describes.Reproduced both the bug and the fix with a standalone script stubbing
xPDO'sgetCollection()/getObject()/newObject()against the resolver's actual logic: with a policy onAdministratorTemplateand one on an unrelatedElementTemplate, the original code addedformit => trueto both; this fix only adds it to theAdministratorTemplateone, leaving the unrelated policy'sdatauntouched.Fix: build a template id → name lookup while walking the templates in the first loop, then skip a policy in the second loop whenever its template isn't in the permission's
templateslist.See #246 for the broader question of whether FormIt should own its own policy template instead of piggybacking on
AdministratorTemplate. This PR doesn't attempt that redesign, it just stops the current approach from leaking into policies it has no business touching.Fixes #272