Skip to content

fix: rate limit guest-writable routes and drop deployment write grants - #14405

Merged
abnegate merged 5 commits into
mainfrom
fix/semgrep-route-limits
Oct 13, 2026
Merged

abnegate merged 5 commits into
mainfrom
fix/semgrep-route-limits

Conversation

@abnegate

@abnegate abnegate commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Fixes the five Semgrep warnings main reports on routes that guests can reach (flagged on #11649 because that PR touches these files).

Rate limits (guest-write-without-abuse-limit). These routes had no abuse labels, so no limit applied:

  • PUT /v1/storage/buckets/:bucketId/files/:fileId: its 60 requests per 60s limit was lost when storage moved into the Storage module. It now uses the same labels as file delete.
  • PATCH /v1/teams/:teamId/memberships/:membershipId/status: this route checks a membership secret. It now allows 10 requests per caller IP and URL. The URL names the team and membership, so changing the userId in the request does not reset the limit.
  • POST /v1/{databases,documentsdb,tablesdb,vectorsdb}/transactions/:transactionId/operations: these now have the document create limit. All four APIs get it, since they serve the same operation.

Deployment permissions (permissive-write-permission). Deployments were stored with update/delete granted to Role::any(). Every writer runs with authorization disabled: the console, project keys, workers and the CLI. The VCS webhook and executions read inside an authorization skip. So the grants opened writes without letting any real caller in. Deployments now get read(any) only, from Deployments::permissions(). The template routes and Compute\Base now use that helper instead of their own copies of the old list.

The Semgrep baseline is regenerated to drop the fixed entries.

Test Plan

  • Abuse lane (abuseEnabled group): file update is now in the group (it got 200 for every request before this change), plus new tests for membership status (10 with a new user ID each time, then 429) and transaction operations for Databases and TablesDB (120, then 429).
  • Sites e2e: a template deployment can be read, listed and deleted with a project key (SitesCustomServerTest) and from the console (SitesConsoleClientTest). A project user gets 401 on cancel and delete, and the deployment remains (SitesCustomClientTest).
  • Full PHPStan passes locally, and the local Semgrep run reports 0 new findings.

Related PRs and Issues

🤖 Generated with Claude Code

abnegate and others added 3 commits October 13, 2026 16:21
Three state-changing routes that guests can reach had no abuse labels,
so the shared api hook applied no limit to them:

- File update lost its limit (60 per 60s) when the storage controller
  moved into the Storage module. It now has the same key, limit and
  period as file delete.
- Membership status update checks a membership secret. It now has the
  same limit and key as the other secret-checking routes, such as the
  recovery confirmation: 10 per user and URL.
- Transaction operation create stages document writes, so it now has
  the document create limit. All four APIs (Databases, DocumentsDB,
  TablesDB, VectorsDB) get the same limit, since they serve the same
  operation.

The new Abuse lane tests cover each route. testAbuseUpdateFile is now in
the abuseEnabled group; it got 200 for every request before this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every deployment was stored with update and delete permissions for
Role::any(). Its writers are the console and project keys, which run
with authorization disabled. The build, delete and maintenance workers
and the CLI also run with it disabled, and the VCS webhook and execution
paths read inside an authorization skip. So the grants opened writes to
anyone without letting any real caller in.

Deployments now get read access only, from one definition,
Deployments::permissions(). The template deployment routes and
Compute\Base now use it instead of their own copies of the old list.

New e2e tests: a template deployment can still be read, listed and
deleted with a project key and from the console, and a project user
cannot cancel or delete one.

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

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

Copy link
Copy Markdown

Review complete. No blocking issues — 2 nitpicks below.

🧹 Nitpicks (2) — 🟢 2 low
  • 🟢 testAbuseUpdateFile only runs when Account paths change (AbuseTest.php:323) — testAbuseUpdateFile carries #[Group('abuseEnabled')] (tests/e2e/General/AbuseTest.php:323), so every regular service lane skips it via --exclude-group abuseEnabled (.github/workflows/ci.yml:773); it runs only in the Abuse grouped lane.
  • 🟢 assertGuestLimited IP pool invites cross-run bucket collisions (AbuseTest.php:533) — assertGuestLimited draws x-forwarded-for from only 254 addresses (tests/e2e/General/AbuseTest.php:533), so concurrent or repeated runs of the abuse group can share one IP bucket and consume each other's budget.

This change centralizes deployment document permissions in Deployments::permissions() (read-only for any role), routes the Compute and Sites template-deployment flows through it, and adds abuse rate-limit labels plus new e2e tests covering guest throttling and template-deployment authorization.

Files Change
src/Appwrite/Deployment/Deployments.php, src/Appwrite/Platform/Modules/Compute/Base.php, src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php Deployment $permissions reduced to read(Role::any()) via a newly public shared helper used by all three call sites.
Transaction/Storage/Teams Create.php/Update.php routes abuse-key/abuse-limit labels added to transaction operations, file update, and membership status endpoints.
tests/e2e/General/AbuseTest.php, tests/e2e/Services/Sites/* New guest-throttle assertions (grouped abuseEnabled), a template-deployment helper, and authorization tests for console, project-key, and project-user sides.

Reviewed commit: 0807a29

@ghost

ghost commented Oct 13, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This PR adds guest abuse limits to file updates, membership-status updates, and transaction-operation routes, then centralizes deployment permissions as public read-only access across compute and template-deployment paths. It refreshes the Semgrep baseline and adds e2e coverage for the limits and deployment access behavior. The console workflows also clarify the pinned GitHub App token action version.

Latest changes: The membership-status abuse key now uses IP plus URL instead of the caller-supplied user ID, and its abuse test varies user IDs to verify that doing so does not reset the limit.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 17
File Change
.github/workflows/console-production.yml Clarifies the pinned GitHub App token action version.
.github/workflows/console-staging.yml Clarifies the pinned GitHub App token action version.
.semgrep/baseline.json Removes fixed Semgrep findings and refreshes baseline line references.
src/Appwrite/Deployment/Deployments.php Centralizes deployment permissions as public read-only access.
src/Appwrite/Platform/Modules/Compute/Base.php Uses the shared deployment permissions for function and site deployments.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php Adds an abuse limit to database transaction operations.
src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Operations/Create.php Adds an abuse limit to DocumentsDB transaction operations.
src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Operations/Create.php Adds an abuse limit to TablesDB transaction operations.
src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Operations/Create.php Adds an abuse limit to VectorsDB transaction operations.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php Uses the shared deployment permissions for template deployments.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php Adds the standard write abuse limit to file updates.
src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php Adds membership-status abuse limiting keyed by IP and URL.
tests/e2e/General/AbuseTest.php Covers abuse limits and verifies changing user IDs cannot reset the membership-status limit.
tests/e2e/Services/Sites/SitesBase.php Adds helpers for template deployment e2e coverage.
tests/e2e/Services/Sites/SitesConsoleClientTest.php Tests template deployment access from the console.
tests/e2e/Services/Sites/SitesCustomClientTest.php Tests that a project user cannot cancel or delete a template deployment.
tests/e2e/Services/Sites/SitesCustomServerTest.php Tests template deployment access with a project key.

Reviewed the commits since 3988141 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

ghost
ghost previously requested changes Oct 13, 2026

@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 B · 1 blocking finding to address. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • 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.

zizmor fails Checks / Workflows because the pinned commit is tagged
v3.2.0, while the comment says v3, and v3 now points to a newer commit.
The comment now names v3.2.0, the release the hash is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/semgrep-route-limits (after).

Metric Before After Change
🚀 Requests/sec 212.53 203.19 ⚪ -4.4%
⏱️ Latency P50 81.94 ms 85.58 ms ⚪ +4.4%
⏱️ Latency P95 186.73 ms 196.71 ms 🔴 +5.3%
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 85.58 196.71 12,540 203.19 +9.99
Account 166.46 311.22 660 11.42 +33.71
TablesDB 82.14 152.01 6,820 113.37 +0.03
Storage 79.71 172.7 3,300 56.82 +15.72
Functions 125.27 230.95 1,760 31 +20.28

Top API waits (after)

API request Max wait (ms)
account.name.update 511.04
functions.delete 477.69
functions.create 424.26
account.prefs.update 381.07
functions.variables.update 375.04

…quest's user ID

The limit keyed on {param-userId}, which comes from the request. The
secret is checked before the user ID, so a caller could send a new user
ID with each guess and get a fresh limit every time. The key is now the
caller's IP and the URL, which names the team and membership, so
guesses at one membership share one limit. The abuse test now changes
the user ID on every request and still expects the eleventh to be
throttled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate

abnegate commented Oct 13, 2026 •

Copy link
Copy Markdown
Member Author

Re the tenki nitpicks: (1) Rate-limit tests only run in the Abuse lane by design, since every other lane runs with abuse checks disabled. That lane is selected when Account is affected or when a change isn't owned by a single service, as on this PR, where it ran and passed. (2) Each test's limit key also includes a URL with IDs unique to that test, so tests that draw the same forwarded IP never share a limit. 🤖 Addressed by Claude Code

@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

@ghost
ghost dismissed their stale review October 13, 2026 03:43

The findings that requested changes are resolved. See the summary comment for what is still open.

@abnegate
abnegate merged commit 67b6dc3 into main Oct 13, 2026
101 of 105 checks passed
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