Skip to content

fix: gate development-only routes on an explicit development env - #14824

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/mock-routes-production
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/mock-routes-production

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

The development-only mock routes in app/controllers/mock.php (and the time-travel CLI task) read _APP_ENV with a development default, while the server itself defaults to production (app/http.php, app/init/registers.php). A deployment that never set _APP_ENV therefore ran as production everywhere except these gates.

They now default to production, so they only open when _APP_ENV=development is set explicitly. The installer already writes _APP_ENV=production, so standard installs are unaffected.

Tests

The CI stack sets _APP_ENV=development, so the existing e2e tests that use these mock routes keep exercising them (and would fail if the gate closed with the variable set). The changed default only matters when the variable is missing, which the e2e environment cannot express without a separate stack; no new test.

Related: appwrite-labs/cloud#6674

Mock routes and the time-travel task treated a missing _APP_ENV as development while the server defaults to production.
@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 — Mock JWKS and id-token routes bypass the new dev gate · mock.php:272–332 · unchanged line

// app/controllers/mock.php
272	Http::get('/v1/mock/tests/general/oauth2/jwks')
273	    ->desc('OAuth2 JWKS')
274	    ->groups(['mock'])
275	    ->label('scope', 'public')
276	    ->label('docs', false)
277	    ->label('mock', true)
278	    ->inject('response')
279	    ->inject('cache')
280	    ->inject('lock')
281	    ->action(function (Response $response, Cache $cache, Lock $lock) {
282	        $key = (new SigningKey($cache, $lock))->get();
283	        $details = \openssl_pkey_get_details($key);

The PR gates the three state-mutating mock routes on _APP_ENV=development, but GET /v1/mock/tests/general/oauth2/jwks and GET /v1/mock/tests/general/oauth2/id-token (app/controllers/mock.php:272-332) still have no environment check and are registered unconditionally as a service controller. The id-token route RSA-signs arbitrary caller-supplied JSON claims under the mock signing key, and the JWKS route publishes that key's public half. In production, an unauthenticated caller can mint a fully signed ID token with attacker-chosen claims against any project whose mock-native flag was enabled in a development environment and persisted through promotion.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Telemetry span still defaults _APP_ENV to development (span.php) — app/init/span.php:80 still reads System::getEnv('_APP_ENV', 'development') === 'production' ? 'production' : 'staging', keeping the old default this PR removes from mock.php and TimeTravel.php.

This PR closes a dev-mode escape hatch: routes and CLI tasks that previously activated whenever _APP_ENV defaulted to development now run only when development mode is explicitly set, making production the safe default for unset environments.

Files Change
app/controllers/mock.php Adds a _APP_ENV=development gate to the mock controller's mutating routes so they are unavailable outside explicit development mode.
src/Appwrite/Platform/Tasks/TimeTravel.php Applies the same explicit-development gate to the TimeTravel CLI task before any timestamp mutation runs.

Two residual gaps remain: the mock JWKS/id-token GET routes still bypass the gate, and app/init/span.php keeps the old development default for telemetry labeling.

Reviewed commit: 138f838

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new fallback matches the server’s production default, and the explicitly configured development path remains unchanged.

Development-only mock endpoints and the time-travel task now treat an unset _APP_ENV as production. They remain available when _APP_ENV=development is explicitly set.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/controllers/mock.php Changed the three mock-route environment fallbacks to production.
src/Appwrite/Platform/Tasks/TimeTravel.php Changed the task’s environment fallback to production.

Reviewed 138f838 · 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

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/mock-routes-production (after).

Metric Before After Change
🚀 Requests/sec 217.54 217.55 ⚪ 0%
⏱️ Latency P50 78.06 ms 79.98 ms ⚪ +2.5%
⏱️ Latency P95 188.58 ms 183.94 ms ⚪ -2.5%
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 79.98 183.94 13,680 217.55 -4.64
Account 147.7 288.82 720 12.15 +11.54
TablesDB 78.09 144.25 7,440 120.35 +6.79
Storage 71.21 171.38 3,600 60.1 -14.06
Functions 113.91 214.81 1,920 32.81 -14.48

Top API waits (after)

API request Max wait (ms)
account.name.update 527.6
functions.create 464.87
tablesdb.rows.create 387.58
account.get 365.28
account.prefs.update 353.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 678ec9d into main Oct 22, 2026
119 of 121 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/mock-routes-production branch October 22, 2026 17:35
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
…ction

fix: gate development-only routes on an explicit development env
(cherry picked from commit 678ec9d)
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