Skip to content

fix(organization): accept only keys and console sessions on organization routes - #14779

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/organization-console-sessions
Oct 22, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/organization-console-sessions

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Organization routes (/v1/organization/*) resolve the organization from the project named in the request. Outside the console project they now require an API key or a console session in admin mode, so a project end-user session is refused and organization access is always checked against the organization's platform membership rather than the project's own teams.

Changes

  • Organization/Http/Init.php: refuse requests on a non-console project that carry neither an API key nor admin mode, with user_unauthorized. Console project requests and key-authorized requests are unchanged; admin-mode requests continue through the shared API hook's membership check.

Tests

  • New tests/e2e/Services/Organization/ProjectsCustomClientTest.php: a project user who owns a project team whose ID matches the organization ID gets 401 on organization project list, get, key list and key create; a console admin-mode session and a project API key still list keys. E2E is verified by the Organization CI lane.

Related: appwrite-labs/cloud#6666

…ion routes

Organization routes resolve the organization from the project in the
request, so a project session reached them with roles built from the
project's own teams. Outside the console project, require an API key or a
console session in admin mode, which the shared API hook checks against
the organization's platform membership.

Co-Authored-By: Claude <[email protected]>
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Assert error type on all 401 failure cases (ProjectsCustomClientTest.php:50) — Only the first FAILURE call asserts the response body type user_unauthorized; the GET project, GET keys, and POST keys failure cases (tests/e2e/Services/Organization/ProjectsCustomClientTest.php:50-60) assert only the 401 status code.

The change introduces an init hook in src/Appwrite/Platform/Modules/Organization/Http/Init.php that gates all organization-group actions: non-console projects throw USER_UNAUTHORIZED, console projects require a valid API key, and missing teams throw TEAM_NOT_FOUND. The gate's DI injections (project, mode, apiKey) match registered resources, admin-mode spoofing is caught downstream by scope checks, and no cross-file or architectural defects were found. The new e2e suite tests/e2e/Services/Organization/ProjectsCustomClientTest.php verifies that a project-scoped client session receives 401 on list/create project and key routes.

Files Change
src/Appwrite/Platform/Modules/Organization/Http/Init.php Adds the organization init authorization gate checking project, mode, API key, and team membership.
tests/e2e/Services/Organization/ProjectsCustomClientTest.php Adds e2e coverage asserting 401 rejections for project-scoped sessions across four organization routes.

Reviewed commit: 6a4a13b

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change only removes assertions that over-specify the error type for two routes and introduces no defect.

Organization routes now reject project end-user sessions on non-console projects while allowing API keys and console admin-mode sessions. The new E2E test exercises the rejected project-session routes and verifies successful key listing through admin mode and a project API key.

Latest changes: The latest commit removes the user_unauthorized type assertions for key listing and creation, retaining the 401 status checks where those routes may be rejected before the organization hook responds.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Organization/Http/Init.php Rejects non-console organization requests without an API key or admin mode.
tests/e2e/Services/Organization/ProjectsCustomClientTest.php Covers project-session rejection and successful key listing through admin mode and a project API key; the latest commit keeps status checks without requiring a specific error type on key routes.

Reviewed the commits since 9eda928 · 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

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/organization-console-sessions (after).

Metric Before After Change
🚀 Requests/sec 195.95 187.35 ⚪ -4.4%
⏱️ Latency P50 87.11 ms 92.33 ms 🔴 +6%
⏱️ Latency P95 209.78 ms 217.34 ms ⚪ +3.6%
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 92.33 217.34 11,628 187.35 +7.56
Account 171.48 326.48 612 10.13 +30
TablesDB 89.25 167.88 6,324 104.14 +7.49
Storage 85.44 194.58 3,060 52.3 +9.18
Functions 135.91 252.86 1,632 28.65 +1.27

Top API waits (after)

API request Max wait (ms)
account.name.update 497.54
functions.variables.update 402.93
functions.delete 392.63
account.prefs.update 384.27
storage.buckets.create 371.46

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

…ook answers first

The key routes need key scopes a project session never holds, so the
scope check refuses them before the organization hook runs.

Co-Authored-By: Claude <[email protected]>
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Re the tenki nitpick on asserting the error type: the list and get routes now also assert user_unauthorized. The two key routes keep a status-only check, because they need key scopes a project session never has, so the shared scope check refuses them (general_unauthorized_scope) before the organization hook runs. Either way the request is refused with 401.

@ChiragAgg5k
ChiragAgg5k merged commit bf06dcb into main Oct 22, 2026
31 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/organization-console-sessions branch October 22, 2026 18:19
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…ion routes (backport #14779)

On a non-console project, a project session whose project team shared the organization ID counted as organization membership. Outside the console, organization routes now accept only API keys and console sessions in admin mode. The organization key routes do not exist on 1.9, so their test calls are dropped.

(cherry picked from commit bf06dcb)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…ion routes (backport #14779)

On a non-console project, a project session whose project team shared the organization ID counted as organization membership. Outside the console, organization routes now accept only API keys and console sessions in admin mode. The organization key routes do not exist on 1.9, so their test calls are dropped.

(cherry picked from commit bf06dcb)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…ion routes (backport #14779)

On a non-console project, a project session whose project team shared the organization ID counted as organization membership. Outside the console, organization routes now accept only API keys and console sessions in admin mode. The organization key routes do not exist on 1.9, so their test calls are dropped.

(cherry picked from commit bf06dcb)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…ion routes (backport #14779)

On a non-console project, a project session whose project team shared the organization ID counted as organization membership. Outside the console, organization routes now accept only API keys and console sessions in admin mode. The organization key routes do not exist on 1.9, so their test calls are dropped.

(cherry picked from commit bf06dcb)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…ion routes (backport #14779)

On a non-console project, a project session whose project team shared the organization ID counted as organization membership. Outside the console, organization routes now accept only API keys and console sessions in admin mode. The organization key routes do not exist on 1.9, so their test calls are dropped.

(cherry picked from commit bf06dcb)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…ole-sessions

fix(organization): accept only keys and console sessions on organization routes

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