Skip to content

fix(deployments): check the read scope for key downloads - #15460

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/deployment-download-key-scope
Nov 10, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/deployment-download-key-scope

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

The deployment download action treats API keys as privileged without looking at their scopes. It now requires functions.read / sites.read, matching the route's label. Presigned-token and console access are unchanged.

Covered by an added assertion in the existing deployment download e2e test.

Related: appwrite-labs/cloud#6673

Every API key now holds the public scope, which this route also accepts for presigned tokens, and the action let any key through. A key with any single scope could download every function and site deployment's source and build output.
@luxor-code-review

luxor-code-review Bot commented Nov 10, 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 — Add unscoped-key 401 e2e coverage for Sites download · tests/e2e/Services/Sites/SitesCustomServerTest.php

The PR adds the sites.read key-scope gate to the Sites deployment download handler but only asserts the new 401 behavior for Functions (tests/e2e/Services/Functions/FunctionsCustomServerTest.php:1378). testSiteDownload in tests/e2e/Services/Sites/SitesCustomServerTest.php:3718 has no equivalent unscoped-key assertion, so a Sites-side regression (e.g. a wrong scope string) would not fail any e2e lane.

The only Functions negative assertion lives inside the #[Group('s3')] test testDeploymentBuildOutputIsServedFromTheBuildsDevice, so even the Functions gate is untested in default CI lanes.


Previously any API key — even one scoped only to users.read — could download deployment artifacts, because the download routes' scope gate includes the implicit public scope and nothing in the handler re-checked a resource-specific scope. The PR adds an in-handler scope check to both download endpoints and covers the Functions side with an e2e assertion.

Files Change
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php, src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php Add a symmetric guard: API-key callers must hold functions.read / sites.read respectively or receive USER_UNAUTHORIZED; privileged users and presigned-token paths are unaffected.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php New e2e assertion that an unscoped key (users.read) gets 401 on deployment download, inside the s3-grouped build-output test.

The authorization change itself is sound: both handlers were verified for symmetric scope strings, unreachable-by-request getScopes() input, and intact presigned-token and privileged-user paths. The main gap is test coverage asymmetry — the Sites endpoint gets no equivalent negative assertion, and even the Functions one only runs in the s3 lane.

Reviewed commit: 1a6d939

@ChiragAgg5k ChiragAgg5k changed the title fix(deployments): require the read scope for key downloads fix(deployments): check the read scope for key downloads Nov 10, 2026
@appwrite

appwrite Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Function and site deployment downloads now require the corresponding functions.read or sites.read scope for API-key access, while preserving access for privileged callers and valid presigned tokens. The deployment e2e tests verify that keys limited to users.read are rejected for both artifact downloads.

Latest changes: The latest commits switch both download actions to Appwrite's request wrapper, which provides the authenticated caller's scopes to the new checks.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php Require functions.read for API-key downloads and use the Appwrite request wrapper to read caller scopes.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php Require sites.read for API-key downloads and use the Appwrite request wrapper to read caller scopes.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Verify that a key limited to users.read cannot download a function deployment.
tests/e2e/Services/Sites/SitesCustomServerTest.php Verify that a key limited to users.read cannot download a site deployment.

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

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

🔵 Tier A · Looks good to merge. Summary

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

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/deployment-download-key-scope (after).

Metric Before After Change
🚀 Requests/sec 192.35 207.7 🟢 +8%
⏱️ Latency P50 87.01 ms 84.46 ms ⚪ -2.9%
⏱️ Latency P95 216.53 ms 191.72 ms 🟢 -11.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 84.46 191.72 12,825 207.7 -24.81
Account 155.49 278.04 675 11.2 -45.7
TablesDB 81.61 147.68 6,975 114.93 -16.83
Storage 79.37 183.63 3,375 57.84 -4
Functions 119.52 222.88 1,800 31.57 -60.57

Top API waits (after)

API request Max wait (ms)
account.name.update 437.94
account.prefs.update 417.54
functions.create 373.35
storage.buckets.create 345.04
functions.variables.update 340.13

@ChiragAgg5k
ChiragAgg5k merged commit ef64119 into main Nov 10, 2026
38 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/deployment-download-key-scope branch November 10, 2026 13:44
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 11, 2026
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
…cope

fix(deployments): check the read scope for key downloads

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