Repository navigation
fix(projects): require owner on both organizations to transfer a project - #14780
Conversation
Moving a project rewrites its team and permissions, so it hands the project to whoever owns the destination organization. Only a confirmed team-wide owner of both the current and the destination organization may do that; developers and project-scoped roles keep projects.write for everything else.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This change tightens
Reviewed commit: 07f7923 |
🟢 Tier S · Ready to merge
Project team transfers now require a confirmed owner membership for the caller on both the current and destination organizations. An E2E test covers denied transfers for non-owners and transfers by an owner of both organizations.
📂 Walkthrough · 2
Reviewed |
There was a problem hiding this comment.
This PR adds an ownership gate to the project team-transfer endpoint, requiring the caller to be an owner of both the source and destination organizations, with a matching e2e test.
Key findings
- 🟡 Owner gate breaks API-key-authenticated project transfers — Update.php:71
| if ( | ||
| !$this->isOwner($dbForPlatform, $targetUser, $project->getAttribute('teamInternalId', '')) | ||
| || !$this->isOwner($dbForPlatform, $targetUser, $team->getSequence()) | ||
| ) { | ||
| throw new Exception(Exception::USER_UNAUTHORIZED, 'Transferring a project requires the owner role on both the current and the destination organization.'); | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Owner gate breaks API-key-authenticated project transfers
The new ownership gate rejects every request whose targetUser is an empty User (src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php:71-76, 113-115). For requests authenticated with a server API key — the auth type this route advertises (AuthType::ADMIN at line 42) — the user resource resolves to an empty document (app/init/resources/request.php:516-521), so isOwner() always returns false and previously working key-authenticated calls to PATCH /v1/projects/:projectId/team now fail with 401 user_unauthorized. SDK and CLI flows using an admin key are broken with no migration note, and the new e2e test only covers session-cookie auth.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php (lines 71-76 and 111-124), relax the new ownership gate so key-authenticated requests are not always rejected: inject the existing apiKey resource (as done in app/controllers/shared/api.php) and skip the isOwner() checks when the caller authenticated with a server API key holding projects.write, keeping the owner-on-both-organizations check for session-authenticated users. Then extend tests/e2e/Services/Projects/ProjectsConsoleClientTest.php with a key-authenticated transfer success case.
There was a problem hiding this comment.
This is intended. A key has no user, so nothing can show that it owns the destination organization. That holds for a project key scoped to the project in the path and for an organization key, which is owner of its own organization only. Moving a project into another organization is exactly what this gate is meant to stop, so transfers now need a signed-in user who owns both organizations. AuthType::ADMIN in the SDK spec already means console-session admin, and that flow keeps working (covered by testTransferProjectTeam and the new success case).
There was a problem hiding this comment.
That's a reasonable design argument, but it rests on an assumption that isn't enforced in code: the local hunk still contains no guard that distinguishes between an empty targetUser (API-key path) and a real session user before calling isOwner(). If the route genuinely cannot be reached by project API keys at the framework/hook level, a defensive early-return or assertion to that effect (e.g. checking $targetUser->isEmpty() and throwing a clearer error, or a code comment citing the hook that blocks non-session callers) would make the intent explicit and prevent a regression if that routing assumption ever changes. As it stands, the code silently fails with a misleading 'owner' error for any non-session caller rather than documenting or asserting the session-only contract.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
…ect (backport #14780) Any member of the source team could move a project into another team. Transfer now requires a confirmed owner membership on both the current and destination organization. 1.9 has no targetUser resource, so the effective user resource is used. (cherry picked from commit b7f9c9c)
…ect (backport #14780) Any member of the source team could move a project into another team. Transfer now requires a confirmed owner membership on both the current and destination organization. 1.9 has no targetUser resource, so the effective user resource is used. (cherry picked from commit b7f9c9c)
…ect (backport #14780) Any member of the source team could move a project into another team. Transfer now requires a confirmed owner membership on both the current and destination organization. 1.9 has no targetUser resource, so the effective user resource is used. (cherry picked from commit b7f9c9c)
…sfer-ownership fix(projects): require owner on both organizations to transfer a project (cherry picked from commit b7f9c9c)
What
PATCH /v1/projects/:projectId/teamnow requires the caller to hold a confirmed, team-wideownermembership on both the project's current organization and the destination organization. Otherwise it returns 401user_unauthorized.Why
Transferring a project rewrites its team and permissions, which hands the project to whoever controls the destination organization.
projects.writeis also granted to thedeveloperrole and to project-scoped roles (project-{id}-developer,project-{id}-owner), which are fine for editing a project but should not be able to move it out of the organization, and nobody should be able to place a project into an organization they do not own.The check reads the caller's membership rows from the platform database directly (
teamInternalId+userInternalId,confirm = true) and requires the exactownerrole, so project-scoped roles never qualify. When impersonating, the impersonated user's memberships are used, matching how the API hook resolves admin roles. Callers without a user (organization keys) can no longer transfer, since ownership of the destination can't be established for them.Tests
New e2e
ProjectsConsoleClientTest::testTransferProjectTeamRequiresOwnership:developer,project-{id}-developerandproject-{id}-owneron the source transferring into an organization they own: 401, and the project stays in its organizationThe existing
testTransferProjectTeamsuccess path (owner of both teams) is unchanged. E2E not run locally (shared machine); relying on the CI Projects lane.Related: appwrite-labs/cloud#6666