Skip to content

fix(auth): harden user update authorization#1081

Merged
perber merged 2 commits into
mainfrom
fix/user-update-authorization
May 30, 2026
Merged

fix(auth): harden user update authorization#1081
perber merged 2 commits into
mainfrom
fix/user-update-authorization

Conversation

@perber
Copy link
Copy Markdown
Owner

@perber perber commented May 30, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 30, 2026 19:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the auth/user-management paths by preventing role escalation via user self-updates and by introducing a safeguard that blocks demoting the last remaining admin user.

Changes:

  • Add RequesterIsAdmin to the UpdateUser use-case input and ignore role changes for non-admin requesters.
  • Prevent demoting the last admin (core auth service + API error mapping + UI localization).
  • Add focused tests covering role escalation prevention and last-admin demotion behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ui/leafwiki-ui/src/locales/en/errors.json Adds localized UI copy for the “last admin cannot be demoted” error template.
internal/wiki/auth/use_cases.go Adds requester context to UpdateUser and conditionally applies/validates role changes.
internal/wiki/auth/use_cases_test.go Adds regression/behavior tests for UpdateUser role handling and last-admin constraints.
internal/wiki/auth/routes.go Makes role optional in the update request payload and passes admin-ness to the use-case.
internal/wiki/auth/errors.go Adds a new auth error code and maps the core error to an API response.
internal/core/auth/user_store.go Adds a store helper to count admin users.
internal/core/auth/user_service.go Blocks demoting the last admin user.
internal/core/auth/user_service_test.go Adds tests for last-admin demotion blocking and demotion when another admin exists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/wiki/auth/use_cases.go Outdated
Comment thread internal/core/auth/user_service.go
Comment thread internal/wiki/auth/use_cases_test.go
@perber perber force-pushed the fix/user-update-authorization branch from 47c6d24 to f88499f Compare May 30, 2026 19:44
Resolve merge conflicts in auth and revision code while preserving the admin role update fix and revision path validation.
@perber perber merged commit 1c2e407 into main May 30, 2026
8 checks passed
@perber perber deleted the fix/user-update-authorization branch May 30, 2026 20:09
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