Skip to content

fix(api): let API keys call public-scope endpoints - #15156

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/api-key-public-scope
Nov 2, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/api-key-public-scope

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Problem

Any API key calling an endpoint with the public scope, such as GET /v1/functions/runtimes or the sites frameworks list, gets missing scopes (["public"]). Key auth replaces the role's scopes with the key's own, and public is not a scope a key can be given. This breaks appwrite init function in CI, which lists runtimes with a key.

Fix

app/controllers/shared/api.php: a key's request scopes are its scopes plus public. Guests already hold public, so this widens nothing. Every key type (standard, ephemeral, dynamic, organization, account) goes through this line. public is still not offered as a selectable key scope.

$scopes = [...$apiKey->getScopes(), 'public'];

Test

FunctionsCustomServerTest::testGetRuntimes now also lists runtimes with only the server API key and asserts 200 and a non-empty list. The existing calls sent no key, so they never hit this path.

Related: appwrite-labs/cloud#6666

Keys carry only the scopes they were given, and 'public' is not one a key
can be given, so every key was refused on routes open to guests, such as
listing function runtimes, which the CLI calls during init.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Security rules

WARNING (2 new) — review signal only; does not fail the job.

php.appwrite.weak-secret-env-default (2)

Secret-like env var (SECRET, KEY, PASS, PASSWORD, TOKEN) read with a non-empty literal default. If the variable is unset the process silently runs with a shared, guessable value. Default to '' and fail or disable the feature when it is empty.

  • src/Appwrite/Auth/EncryptionKey.php:40 — EncryptionKey::version()
    • What's wrong: _APP_OPENSSL_KEY_CURRENT falls back to '1' when unset, so every install that does not set it shares that value.
    • How to fix: Read System::getEnv('_APP_OPENSSL_KEY_CURRENT', '') and fail or disable the dependent connection when it is empty; keep the example value in .env / app/config/variables.php.
  • src/Appwrite/Auth/EncryptionKey.php:64 — EncryptionKey::accepted()
    • What's wrong: _APP_OPENSSL_KEY_OLDEST falls back to '1' when unset, so every install that does not set it shares that value.
    • How to fix: Read System::getEnv('_APP_OPENSSL_KEY_OLDEST', '') and fail or disable the dependent connection when it is empty; keep the example value in .env / app/config/variables.php.
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.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/api-key-public-scope (after).

Metric Before After Change
🚀 Requests/sec 194.37 194.1 ⚪ -0.1%
⏱️ Latency P50 85.98 ms 89.35 ms ⚪ +3.9%
⏱️ Latency P95 213.22 ms 208.7 ms ⚪ -2.1%
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.35 208.7 12,426 194.1 -4.52
Account 172.13 305.85 654 10.89 +1.67
TablesDB 85.45 163.84 6,758 108.5 +10.47
Storage 84.1 187.63 3,270 53.77 -5.43
Functions 126.8 242.14 1,744 29.43 -60.4

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.create 476.5
account.name.update 413.84
functions.create 406.64
storage.buckets.create 382.64
account.prefs.update 377.99

@ChiragAgg5k ChiragAgg5k self-assigned this Nov 2, 2026
@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review November 2, 2026 20:22
@luxor-code-review

luxor-code-review Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change makes API keys implicitly carry the public scope, matching the guest role's baseline access, and locks that behavior in with an e2e test. The scope grant itself is safe because guests already hold public, so no endpoint becomes newly reachable through keys versus the missing-key path.

Files Change
app/controllers/shared/api.php Adds public to the resolved key scope set during request authorization.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Adds an e2e case exercising a key-authenticated request against a public route without a user session.

Reviewed commit: 29b01cc

@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The scope addition matches the existing guest access contract, and the changed behavior has an E2E regression check.

API-key requests now include the public scope, allowing keys to access endpoints marked public without making that scope selectable on keys. The Functions E2E test now checks that a server API key can list runtimes successfully.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/controllers/shared/api.php Adds the public scope to scopes used for API-key requests.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Adds an API-key-authenticated runtimes-listing assertion.

Reviewed 29b01cc · 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
ChiragAgg5k merged commit 88599d8 into main Nov 2, 2026
64 of 65 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/api-key-public-scope branch November 2, 2026 20:26
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