Skip to content

fix(projects): require owner on both organizations to transfer a project - #14780

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/project-team-transfer-ownership
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/project-team-transfer-ownership

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

PATCH /v1/projects/:projectId/team now requires the caller to hold a confirmed, team-wide owner membership on both the project's current organization and the destination organization. Otherwise it returns 401 user_unauthorized.

Why

Transferring a project rewrites its team and permissions, which hands the project to whoever controls the destination organization. projects.write is also granted to the developer role 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 exact owner role, 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:

  • owner of the source organization transferring into an organization they are not a member of: 401
  • developer, project-{id}-developer and project-{id}-owner on the source transferring into an organization they own: 401, and the project stays in its organization
  • owner of both: 200

The existing testTransferProjectTeam success path (owner of both teams) is unchanged. E2E not run locally (shared machine); relying on the CI Projects lane.

Related: appwrite-labs/cloud#6666

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.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Owner gate breaks API-key-authenticated project transfers — Update.php:71

This change tightens PATCH /v1/projects/:projectId/team so that only a confirmed owner of both the source and target organizations can transfer a project between teams, adding an isOwner() membership lookup on each side and a user_unauthorized rejection otherwise. An e2e test covers the success path and several non-owner failure variants. One compatibility issue remains: requests authenticated with a server API key resolve no user, so the gate always rejects them, breaking previously working key-based transfers.

Files Change
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Adds a two-sided owner-membership gate (isOwner() on source teamInternalId and destination team) before honoring a project team transfer.
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php Adds testTransferProjectTeamRequiresOwnership covering 200 for the owner, 401 for a foreign target team, and 401 for non-owner roles on the source team.

Reviewed commit: 07f7923

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The ownership checks use the effective user and the platform memberships, and the new E2E coverage exercises the denial and success paths.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Injects the effective user and verifies confirmed owner membership in both organizations before transferring the project.
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php Adds E2E coverage for ownership failures and the successful owner-of-both transfer.

Reviewed 07f7923 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +71 to +76
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.');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

@ChiragAgg5k ChiragAgg5k Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/project-team-transfer-ownership (after).

Metric Before After Change
🚀 Requests/sec 185.01 206.05 🟢 +11.4%
⏱️ Latency P50 91.26 ms 84.94 ms 🟢 -6.9%
⏱️ Latency P95 226.11 ms 194.12 ms 🟢 -14.1%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 84.94 194.12 12,654 206.05 -31.99
Account 155.83 290.59 666 11.03 -53.14
TablesDB 81.73 146.19 6,882 113.58 -35.05
Storage 78.47 187.95 3,330 57.29 -7.96
Functions 119.08 228.99 1,776 31.3 -23.37

Top API waits (after)

API request Max wait (ms)
account.name.update 539.29
functions.create 417.16
account.prefs.update 359.61
storage.buckets.create 357.54
functions.variables.update 344.78

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k
ChiragAgg5k merged commit b7f9c9c into main Oct 22, 2026
40 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…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)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…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)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…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)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…sfer-ownership

fix(projects): require owner on both organizations to transfer a project

(cherry picked from commit b7f9c9c)
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.

1 participant