Prevent non-logged-in users from viewing user pages located in the admin branch - #357
Open
adrianbj wants to merge 1 commit into
Open
Prevent non-logged-in users from viewing user pages located in the admin branch#357adrianbj wants to merge 1 commit into
adrianbj wants to merge 1 commit into
Conversation
With alternate user templates/parents in use, a user having a frontend-viewable template that gets moved under the admin users parent (e.g. /processwire/access/users/) remained viewable to non-logged-in visitors whenever the guest role carried any user-view-* permission (user-view-[role], user-view-all or user-view-guest), because the viewable branch of PagePermissions::userEditable() granted view access without considering where the user page lives. Since a user page in the admin branch is effectively an admin page, guests should get the login screen there instead. Add a guard so that user pages located within the admin branch are never viewable to users that are not logged in; access then falls back to the inherited admin template settings, producing the login screen. Logged-in users with user-view-* permissions are unaffected, as are user pages kept under front-end parents. Verified end-to-end on a live install: created alternate user template/parent, gave the guest role user-view-frontend-person, and confirmed a guest saw the user page rendered at its admin URL; after the patch the same request produces the login screen, while the same user remained guest-viewable under its front-end parent, and logged-in users (with the same permission) and superusers could still view the moved user. Fixes processwire/processwire-issues#2011
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.
Problem
Resolves processwire/processwire-issues#2011
With alternate user templates/parents in use, a user having a frontend-viewable template that gets moved under the admin users parent (e.g.
/processwire/access/users/) remains viewable to non-logged-in visitors whenever the guest role carries anyuser-view-*permission (user-view-[role],user-view-all, or the newuser-view-guestfrom 203d49c).The cause is that for
Userpages,Page::viewable()delegates entirely toPagePermissions::userViewable()→userEditable(['viewable' => true]), which grants view access fromuser-view-*permission matches without considering where the user page lives — normal template access inheritance (which would otherwise require login under the admin branch) never gets a say. Since a user page under the admin branch is effectively an admin page, a guest should get the login screen there instead.Fix
Add a guard at the top of the viewable branch of
userEditable(): user pages located within the admin branch (rootParentis$config->adminRootPageID) are never viewable to users that are not logged in. Access then falls through to the inherited admin template settings, producing the login screen. Behavior for logged-in users withuser-view-*permissions is unchanged, as is visibility of user pages kept under front-end parents.Verification (live install, 3.0.271 + this patch)
Setup per the steps in the issue: alternate user template
member(pageClassUser) + parent/members/, configuserTemplateIDs/usersPageIDsupdated, rolefrontend-person, optional permissionuser-view-frontend-personinstalled and assigned to the guest role, userbobtestcreated under/members/with that role, then moved to/admin/access/users/bobtest/via the Settings tab parent.Before the patch, a guest request to
/admin/access/users/bobtest/rendered the member template output. After the patch:/admin/access/users/bobtest/→ login screen ✔/members/caroltest/(identical user left under the front-end parent) → still renders ✔user-view-frontend-person) →$bob->viewable()stilltrue✔true✔/members/bobtest/URL returns 404 to guests with no redirect, so the admin URL is not exposed via path history ✔🤖 Generated with Claude Code