Skip to content

fix(keys): hide key secrets from callers without keys.write - #14600

Merged
loks0n merged 1 commit into
mainfrom
claude/api-key-secret-disclosure-623731
Oct 16, 2026
Merged

loks0n merged 1 commit into
mainfrom
claude/api-key-secret-disclosure-623731

Conversation

@loks0n

@loks0n loks0n commented Oct 16, 2026

Copy link
Copy Markdown
Member

What

GET on project keys (/v1/project/keys, /v1/projects/:projectId/keys, /v1/organization/projects/:projectId/keys, and the /:keyId variants) returned every key's secret to any caller with keys.read. A key limited to keys.read could read the secret of a broader key and act with its scopes.

The list and get actions now blank secret when the caller is an API key without keys.write (or organization.projects.keys.write on the organization routes). A caller with write access can already rewrite any key's scopes, so showing it the secret grants nothing new.

Console roles (owner, developer, admin) always hold both scopes, so the Console still shows secrets. Create and ephemeral create still return the secret.

Tests

  • New testGetKeySecretRequiresWriteScope in Organization/KeysBase: a keys.read ephemeral key gets '' on get and list, while a keys.read + keys.write key gets the real secret.
  • Same checks added to the Project/KeysBase lifecycle smoke test.
  • The new test failed on main (secret returned) and passes with this change. Organization and Project key suites pass locally (console + server).

🤖 Generated with Claude Code

A key holding only keys.read could list or get other project keys and
receive their plaintext secrets, then authenticate with their scopes.
Blank the secret for API keys that cannot write keys on the project and
organization key endpoints. Console roles hold both scopes, so the
Console is unaffected.

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

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

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Document conditional secret redaction in key model (Get.php:77) — GET/LIST project keys now return secret as an empty string when the caller is an API key without a write scope (src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php:77), but MODEL_KEY still documents the rule as "Secret key" with a populated example, and the endpoint descriptions say nothing about the redaction (src/Appwrite/Utopia/Response/Model/Key.php:50).

The change masks the secret field on key responses when the caller authenticates with an API key lacking write access, applying the same conditional redaction across both the Organization and Project key endpoints. E2E suites for both services add reader/writer key cases asserting the secret is blanked for read-only callers.

Files Change
src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php, XList.php Conditionally blank secret on organization project-key responses for callers without organization.projects.keys.write or keys.write.
src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php, XList.php Same conditional secret redaction on the project keys endpoints.
tests/e2e/Services/Organization/KeysBase.php, tests/e2e/Services/Project/KeysBase.php Add redaction test cases asserting read-only keys see empty secrets on GET and LIST.

Reviewed commit: fc9c334

@loks0n loks0n self-assigned this Oct 16, 2026
@ghost

ghost commented Oct 16, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No correctness issues found; changed PHP files pass syntax checks.

Project and organization key get/list endpoints now blank the secret field for API-key callers without the relevant write scope. The E2E coverage exercises read-only key access on both route families and confirms writers can still retrieve a secret on the organization route.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Get.php Blanks key secrets for organization-route API keys without either supported write scope.
src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/XList.php Applies the same scope-based secret filtering to listed keys.
src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Get.php Injects the API key and blanks secrets for callers without keys.write.
src/Appwrite/Platform/Modules/Project/Http/Project/Keys/XList.php Applies the project-route secret filter to each listed key.
tests/e2e/Services/Organization/KeysBase.php Tests organization-route get/list secret visibility for read-only and read/write keys.
tests/e2e/Services/Project/KeysBase.php Adds read-only get/list secret checks to the legacy project key lifecycle test.

Reviewed fc9c334 · 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

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.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → claude/api-key-secret-disclosure-623731 (after).

Metric Before After Change
🚀 Requests/sec 209.85 201.67 ⚪ -3.9%
⏱️ Latency P50 82.16 ms 86.06 ms ⚪ +4.8%
⏱️ Latency P95 187.26 ms 199.75 ms 🔴 +6.7%
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 86.06 199.75 12,540 201.67 +12.49
Account 160.36 297.84 660 11.36 +21.26
TablesDB 82.87 155.66 6,820 113.03 +2.75
Storage 81.22 186.23 3,300 56.02 +4.02
Functions 120.1 231.43 1,760 30.68 +13.38

Top API waits (after)

API request Max wait (ms)
functions.create 513.19
tablesdb.rows.create 499.51
account.name.update 409.4
functions.variables.update 382.32
storage.buckets.create 366.49

@loks0n
loks0n merged commit d7b0be3 into main Oct 16, 2026
34 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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