Repository navigation
Hold keys and JWTs to their original grant - #14888
Conversation
A JWT stands in for its session for at most an hour, and the account JWT route already refuses to mint a JWT from one. Creating, changing or minting an ephemeral key from a JWT left behind a credential that outlived it, so the project and organization key routes now refuse JWT callers with key_creation_denied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A key with keys.write could rewrite any key, itself included, to every project scope and no expiry, and could mint ephemeral keys with any scopes, renewing itself without end. An organization key could provision project keys that outlived it. Key now carries its expiry (stored keys from their document, ephemeral and dynamic keys from the token's exp claim) and mayCreate() bounds what a key hands out: no scope it does not hold, and no expiry later than its own (none at all when it expires). Organization keys keep provisioning project scopes through organization.projects.keys.write, within their lifetime. Key create, update and ephemeral routes apply it; an API key still cannot create a stored key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d it Holding keys.write was enough to read every key's secret, so a narrow or expiring key could read a broader or longer-lived one and act with it, and a JWT could read secrets that outlive it. Get and list now return a secret only to a session with the write scope or to a key whose grant covers that key; JWT callers never see secrets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The account JWT route refuses a JWT caller so a JWT cannot outlive itself through the next one; the users JWT route did not, so an admin-mode console JWT could mint project user JWTs. It now refuses JWT callers with user_jwt_creation_denied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 4 nitpicks below. 🧹 Nitpicks (4) — 🟢 4 low
This PR prevents privilege escalation via key delegation: API keys can no longer create, update, or read secrets of other keys beyond their own grant. Each endpoint now refuses
Reviewed commit: 045ef16 |
🟢 Tier S · Ready to mergeThis change carries key expiry through authentication and constrains key creation and updates to the caller’s scopes and lifetime. It also blocks JWT-authenticated key and user-JWT creation, and redacts key secrets from callers that could not have created those keys.
📂 Walkthrough · 17
Reviewed |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
(cherry picked from commit 7cae6fe)
…-grant Hold keys and JWTs to their original grant (cherry picked from commit 7cae6fe)
Summary
Keys and JWTs can no longer hand out more than they hold. A credential stays limited to its original setup: anything it creates or changes gets no scope it doesn't hold and no expiry later than its own, and a JWT can't create keys or the next JWT.
One commit per change:
key_creation_deniedto a request authorized withx-appwrite-jwt, as the account JWT route already does for JWTs.Keynow carries its expiry: stored keys take it from their document, and ephemeral and dynamic keys from the token'sexpclaim.Key::mayCreate()refuses a key with a scope the caller doesn't hold, or with an expiry later than the caller's own; a caller that expires can't create a key that never does. Key update and ephemeral key creation now check their caller (they didn't before), and create keeps refusing API keys outright. Organization keys still give project keys project scopes throughorganization.projects.keys.write, but the keys they create can't outlive them.secretto a session with the write scope, or to a key whose grant covers the key being read. JWT callers never see secrets.POST /v1/users/:userId/jwtsrefuses JWT callers withuser_jwt_creation_denied.Behaviour changes
keys.writecan no longer give a key, itself included, scopes it doesn't hold, and can't remove or extend a key's expiry beyond its own.key_creation_denieddescription now covers these cases.Notes for review
users.write. They act as the user, not as the key, and server-side login flows create them with short-lived function keys.Key(expire:is a new trailing constructor argument).Tests
KeyTestcovers expiry decoding for each key type, and amayCreatematrix (delegation, self-renewal, expiry across timezones, the organization key exception). The new cases fail without the change.Organization\KeysBase::testKeysStayWithinTheirCallersGranttestKeysRefuseJWTCallerstestGetKeySecretRequiresWriteScopeProject\KeysBase::testKeysStayWithinTheirCallersGrantUsersCustomServerTest::testCreateUserJWTRefusesJWTCallers🤖 Generated with Claude Code