Skip to content

fix(api): accept admin mode only from console origins - #14813

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/admin-mode-console-origins
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/admin-mode-console-origins

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

Admin mode requests (x-appwrite-mode: admin) authenticate with the console session. The allowed hostnames and schemes used for CORS, the origin check and redirect validation now leave out the managed project's platform hostnames, platform schemes and site rule domains when the request is in admin mode, so only console hosts can make credentialed admin mode calls. Site rules from _APP_CONSOLE_TRUSTED_PROJECTS (console previews) stay allowed. This also covers console JWT creation through POST /v1/account/jwts in admin mode, which goes through the same origin check.

Requests in default mode keep the existing behaviour: project platform origins are still allowed.

Compatibility

Tools that call admin mode endpoints from a browser page hosted on a project platform origin will get general_unknown_origin. Server side calls without an Origin header and API key calls are unaffected.

Tests

New e2e tests/e2e/General/AdminModeOriginTest.php: admin mode GET /v1/users and POST /v1/account/jwts succeed from the console origin and are refused (403, no CORS grant) from a registered web platform origin, while a default mode GET /v1/account from that platform origin still succeeds with the CORS grant. Pint, PHPStan and Rector pass locally; e2e runs in CI.

Related: appwrite-labs/cloud#6666

Admin mode authenticates with the console session, so its CORS and origin allowlists must not include the managed project's platform hostnames, custom schemes or site rules. Console preview rules from trusted projects are kept.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Realtime origin validator misses admin-mode restriction · app/init/realtime/connection.php

The new admin-mode tightening in app/init/resources/request.php (lines 272 and 307) excludes project platform hostnames and schemes when the request is in admin mode, but the realtime originValidator in app/init/realtime/connection.php was not updated and still adds all project platform hostnames and schemes unconditionally. The rule-domain allowlist also diverges: HTTP now gates it on _APP_CONSOLE_TRUSTED_PROJECTS (app/init/resources/request.php:292), while realtime adds the rule domain without any admin-mode gate at line 147. An admin-mode realtime connection therefore still accepts origins the hardened HTTP path now rejects.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Trusted-projects env entries not trimmed (request.php:292) — The new trusted-project parsing at app/init/resources/request.php:292 uses array_filter(explode(',', ...)), which removes empty strings but keeps whitespace-padded entries.

The change tightens admin-mode origin handling in the request resource and locks the new behavior in with an e2e test. The main gap is that the realtime origin validator still follows the old, permissive allowlist, so admin-mode WebSocket origins are validated less strictly than HTTP ones.

Files Change
app/init/resources/request.php In admin mode, stops merging platform hostnames/schemes into the origin allowlist and gates rule-domain inclusion on _APP_CONSOLE_TRUSTED_PROJECTS.
tests/e2e/General/AdminModeOriginTest.php Adds an e2e test asserting admin-mode requests from non-console origins are rejected and console-origin requests succeed.
app/init/realtime/connection.php (unchanged, related) Realtime origin validation was not updated, leaving an inconsistency with the new HTTP behavior.

Reviewed commit: 215741a

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed allowlists reject project-platform origins for actual admin-mode requests while preserving default-mode behavior.

Admin-mode requests now exclude project-managed platform hosts, schemes, and non-trusted site-rule domains from the request allowlists, while default mode retains its existing origins. The new end-to-end test exercises admin-mode user and JWT calls from console and project origins, and confirms default-mode access from a project origin remains available.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/init/resources/request.php Make allowed hostnames and schemes depend on request mode, and restrict admin-mode site-rule hosts to trusted console projects.
tests/e2e/General/AdminModeOriginTest.php Add end-to-end coverage for console-origin admin calls, rejection from a project platform origin, and unchanged default-mode access.

Reviewed 215741a · 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

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Thanks. The realtime connection builds its own origin validator and its admin mode handling is being changed separately in #14790, so I kept this PR to the HTTP request allowlists. The realtime origin restriction for admin mode is tracked for that work rather than here.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/admin-mode-console-origins (after).

Metric Before After Change
🚀 Requests/sec 193.11 190.25 ⚪ -1.5%
⏱️ Latency P50 87.81 ms 89.7 ms ⚪ +2.2%
⏱️ Latency P95 213.07 ms 213.02 ms ⚪ 0%
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 89.7 213.02 12,027 190.25 -0.05
Account 178.17 333.99 633 10.48 +16.29
TablesDB 86.89 163.82 6,541 105.98 -8.67
Storage 80.46 192.55 3,165 53.57 +2.56
Functions 127.39 254.21 1,688 29.34 +8.81

Top API waits (after)

API request Max wait (ms)
account.name.update 545.11
functions.create 434.48
storage.files.create 420.35
tablesdb.rows.create 419.44
storage.buckets.create 401.86

@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 244d047 into main Oct 22, 2026
68 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…e-origins

fix(api): accept admin mode only from console origins

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