Skip to content

Fixes #35840: only admins can change a user's domains - #35845

Merged
manerow merged 2 commits into
mainfrom
fix/35840-user-own-domains
Oct 21, 2026
Merged

manerow merged 2 commits into
mainfrom
fix/35840-user-own-domains

Conversation

@manerow

@manerow manerow commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A rule such as "allow EditAll when hasDomain()" lets users edit assets in their domains. But any user could add a domain to their own profile, with PATCH /v1/users/{id} or PUT /v1/users, and hasDomain() then treated them as a member. They could edit that domain's assets and move them into their own domain, getting around the fix for #33420 (PR #33471). Through PUT this also worked for users with DomainOnlyAccessRole, and a non-admin allowed to edit other users could give them any domain.

Why it happened

Every user owns their own profile, so the default owner rule lets them change any field of it. UserResource already keeps the fields that grant access out of that rule: roles, isAdmin, isBot and closed teams need an admin. Domains grant access too, through hasDomain(), but were not on that list.

What this PR changes

Domains join those admin-only checks in UserResource, with no new mechanism:

  • PATCH: any operation on /domains needs an admin, as /roles does.
  • PUT: adding a domain the user does not already hold as their own needs an admin, as adding a role does. A domain inherited from a team does not count, since it goes when the user leaves the team. Sending the domains they already have, or none, works as before.
  • POST and self sign-up: naming domains needs an admin.

The rule is recorded in docs/decisions.

What users will notice

  • Non-admins, including bots, get 403 when they change a user's domains, their own or someone else's. The profile page already showed that control to admins only.
  • Every other self-edit (display name, description, personas, default domain) is unchanged. The default domain only filters what a user sees.

How it was tested

  • Seven new tests in UserResourceIT cover each path above, another user's domains, and two controls (a self-edit keeps the user's domain; an admin sets domains). On main the four that change behavior fail; the whole-document one and the two controls pass, since a whole-document patch was already admin-only. All seven pass here, on Postgres and MySQL.
  • 27 suites on users, teams, personas and domain access (1,864 tests) pass on Postgres. On MySQL one persona paging test failed because another suite added a persona between its two list calls; alone it passes, here and on main.
  • Live, on servers built from main and from this branch: every way above of adding a domain returned 200 on main and let the user edit the new domain's tables; here each returns 403 and stores nothing. Admin edits and other self-edits behave the same on both.
  • No unit test: the integration tests exercise these request checks end to end.

Not in this PR

  • Domains users inherit through their teams: who may change a team's domains, or leave a team, is unchanged and will be handled separately.
  • Teams are still joinable by default; make a team that carries a domain non-joinable.

Fixes #35840

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the previous test gap addressed.

Summary

The PR restricts assigning domains to users to admins and records that decision.

  • Only admins can change a user's domain memberships.

Reviews (2) · Last reviewed commit: "Test that a team's domain cannot be clai..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 21, 2026 08:20
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 21, 2026
@gitar-bot

gitar-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Making domain assignments admin-only across PATCH, PUT, and POST changes authorization; a bypass could let users self-grant access to domain assets.

Restricts user domain changes to admins by adding domains to the existing admin-only checks in UserResource, covering PATCH, PUT, POST, and self sign-up paths. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow added this pull request to the merge queue Oct 21, 2026
manerow added a commit that referenced this pull request Oct 21, 2026
…35845) (#35846)

* Fixes #35840: only admins can change a user's domains

* Test that a team's domain cannot be claimed as a user's own through PUT
Merged via the queue into main with commit 0d1a94d Oct 21, 2026
91 checks passed
@manerow
manerow deleted the fix/35840-user-own-domains branch October 21, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Users can add domains to their own profile and widen their hasDomain() access

2 participants