Skip to content

Prevent non-logged-in users from viewing user pages located in the admin branch - #357

Open
adrianbj wants to merge 1 commit into
processwire:devfrom
adrianbj:fix-admin-users-guest-view
Open

Prevent non-logged-in users from viewing user pages located in the admin branch#357
adrianbj wants to merge 1 commit into
processwire:devfrom
adrianbj:fix-admin-users-guest-view

Conversation

@adrianbj

Copy link
Copy Markdown
Contributor

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 any user-view-* permission (user-view-[role], user-view-all, or the new user-view-guest from 203d49c).

The cause is that for User pages, Page::viewable() delegates entirely to PagePermissions::userViewable()userEditable(['viewable' => true]), which grants view access from user-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 (rootParent is $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 with user-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 (pageClass User) + parent /members/, config userTemplateIDs/usersPageIDs updated, role frontend-person, optional permission user-view-frontend-person installed and assigned to the guest role, user bobtest created 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:

  • guest at /admin/access/users/bobtest/ → login screen ✔
  • guest at /members/caroltest/ (identical user left under the front-end parent) → still renders ✔
  • logged-in non-superuser (inherits guest's user-view-frontend-person) → $bob->viewable() still true
  • superuser → still true
  • the old /members/bobtest/ URL returns 404 to guests with no redirect, so the admin URL is not exposed via path history ✔

🤖 Generated with Claude Code

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
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