fix(trustlab): enforce role-based Payload content access#1473
Merged
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
koechkevin
reviewed
May 13, 2026
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.
Description
@/trustlab's Payload access layer had two categories of issues.Authorization gaps (P1):
Boolean(user), so any authenticated session, regardless of role, could create, update, or delete these collections.create/update/deleteaccess at all, relying on Payload's implicit behaviour.SiteSettingswas world-readable:loggedInwas defined as(user) => Boolean(user)but wired as a Payload access adapter, so Payload called it asloggedIn({ req }), which was always truthy.Structural issues that made auditing difficult:
({ req: { user } }) => helper(user)everywhere.Boolean(user)trusts any truthyreq.uservalue; a token with an arbitrary payload would pass.Changes
Access layer refactor (
src/payload/access/)Introduces a clear three-tier naming convention:
isXxx(user)booleancanXxx(user)boolean | Payload where-filterhasXxxAccess({ req })access:confighasValidRole(user)added toroles.js: validatesuser.roleagainst the known role constants. ReplacesBoolean(user)everywhere.loggedIn.jsremoved.isLoggedIn,isEditor,isAuthor,isAdmin,canAuthor,canManageUserare the new user-level predicates.hasLoggedInAccess,hasEditorAccess,hasAuthorAccess,hasAdminAccess,hasManageUserAccess,hasCreateUserAccessare the new Payload adapters, each a thin wrapper over the corresponding predicate.Collections and globals
Boolean(user)hasEditorAccesscanManagePages(user)inlinehasEditorAccesshasEditorAccesscanManageContent(user)inlinehasAuthorAccesshasCreateUserAccessloggedIn(broken — alwaystrue)hasLoggedInAccesscanManageSiteSettingsinlinehasAdminAccessPosts and Media intentionally remain on
hasAuthorAccessto preserve the ownership-aware author workflow.Preview route
preview/route.tsnow usesisAuthor(user), the correct boolean predicate, instead of the oldcanManageContent(user)whose filter-object return value was only coincidentally truthy in a boolean context.Tests (
src/payload/access/index.test.js)Full policy matrix at the helper layer:
isAuthor,canAuthor,hasAuthorAccess,hasEditorAccess,hasAdminAccess,hasLoggedInAccess,hasCreateUserAccess,hasManageUserAccess, andanyone. Cases cover admin/editor/author/anonymous and invalid-role shapes (role: "unknown", bare integer,undefined). ThecanAuthorsuite includes the id-guard edge case (author with noidreturnsfalserather than a filter withequals: undefined).Type of change
Please delete options that are not relevant.
Screenshots
N/A
Checklist: