Skip to content

Enforce "self or admin" authorization on PATCH /users/{id} - #21

Merged
Mats057 merged 3 commits into
bugfix/missing-role-and-ban-managementfrom
copilot/sub-pr-20
Mar 1, 2026
Merged

Enforce "self or admin" authorization on PATCH /users/{id}#21
Mats057 merged 3 commits into
bugfix/missing-role-and-ban-managementfrom
copilot/sub-pr-20

Conversation

Copilot AI commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Any authenticated user could modify another user's username, email, name, or bio by targeting their id — only the role/accountNonLocked fields had an admin guard.

Changes

  • Auth.java — Added USER_SELF_OR_ADMIN SpEL constant, mirroring the existing REVIEW_OWNER_OR_ADMIN pattern:
    public static final String USER_SELF_OR_ADMIN =
        "@userService.isSelf(#id, authentication.principal.username) or hasRole('ADMIN')";
  • UserService — Added isSelf(UUID id, String username) authorization helper (mirrors ReviewService.isOwner)
  • UserController — Added @PreAuthorize(USER_SELF_OR_ADMIN) to PATCH /users/{id}

The existing admin-only guard inside update() for role/accountNonLocked is retained — users cannot elevate their own role or toggle their lock status.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: Mats057 <119885089+Mats057@users.noreply.github.com>
Copilot AI changed the title [WIP] Update user management role and verification patterns Enforce "self or admin" authorization on PATCH /users/{id} Mar 1, 2026
@Mats057
Mats057 marked this pull request as ready for review March 1, 2026 22:31
@Mats057
Mats057 merged commit 03fa0df into bugfix/missing-role-and-ban-management Mar 1, 2026
@Mats057
Mats057 deleted the copilot/sub-pr-20 branch March 1, 2026 22:32
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.

2 participants