Repository navigation
fix(graphql): keep the caller's identity across fields of one request - #14820
Conversation
Token and recovery issuance loaded the recipient into the request-scoped user and granted its role on the shared authorization. GraphQL fields of one request share those resources, so later fields saw the recipient. Load the recipient into a local document and create the token under skip instead. Scope the roles a field grants to that field, and keep one resolver lock per request so it is never dropped while other resolvers wait on it.
|
Review complete. No issues found — approved ✅. This PR fixes cross-identity role leakage when issuing tokens and hardens GraphQL request-scoped state. Token endpoints no longer grant the caller extra roles mid-request or mutate the injected user document; instead a local recipient document is built and token creation runs under an authorization skip. Resolvers now snapshot and restore roles around each field execution so grants made by one field cannot persist into sibling fields, and the per-request lock moves from a static map into the DI container as a request-scoped resource.
Reviewed commit: acfc742 |
🟢 Tier S · Ready to merge
The account token and recovery endpoints now keep recipient documents local and perform token persistence without granting recipient roles to the request authorization. GraphQL resolver execution now restores roles after each field and uses a per-request lock, with an end-to-end regression test for caller identity across mutation fields.
📂 Walkthrough · 4
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
|
The magic URL, email and phone token endpoints and the recovery endpoint copied the recipient into the shared user resource and added its role to the shared authorization, so later fields in the same GraphQL operation ran as the recipient. They now use a local recipient and create tokens under authorization skip. Each resolver restores the roles it started with, and the resolver lock is a per-request resource. 1.9 has no recovery OTP endpoint and no Authorization::withRoles, so roles are saved and restored around the field. (cherry picked from commit f3e4c08)
The magic URL, email and phone token endpoints and the recovery endpoint copied the recipient into the shared user resource and added its role to the shared authorization, so later fields in the same GraphQL operation ran as the recipient. They now use a local recipient and create tokens under authorization skip. Each resolver restores the roles it started with, and the resolver lock is a per-request resource. 1.9 has no recovery OTP endpoint and no Authorization::withRoles, so roles are saved and restored around the field. (cherry picked from commit f3e4c08)
The magic URL, email and phone token endpoints and the recovery endpoint copied the recipient into the shared user resource and added its role to the shared authorization, so later fields in the same GraphQL operation ran as the recipient. They now use a local recipient and create tokens under authorization skip. Each resolver restores the roles it started with, and the resolver lock is a per-request resource. 1.9 has no recovery OTP endpoint and no Authorization::withRoles, so roles are saved and restored around the field. (cherry picked from commit f3e4c08)
…dentity fix(graphql): keep the caller's identity across fields of one request (cherry picked from commit f3e4c08)
What
GraphQL fields in one request share the request's
userandauthorizationresources. The magic URL, email and phone token endpoints and the recovery and recovery OTP endpoints copied the recipient into the injecteduserand added the recipient's role to the shared authorization. Inside one GraphQL operation, later fields then ran with that identity.$recipientdocument, no longer injectuser, and create their tokens under$authorization->skip()instead of granting the recipient's (or a placeholder's) role.Resolvers::resolve()runs each field inside$authorization->withRoles($authorization->getRoles(), ...), so roles a field adds end with that field. The api init hook still derives roles from the request's user for every field.resolverLockresource instead of a static map entry that each resolver removed in itsfinally. Removing it there let resolvers that started later get a new lock while another coroutine still waited on the old one. The lock now lives for the whole request, so resolvers stay serialized.Compatibility
Audit entries for token and recovery issuance from an unauthenticated request are now recorded with the guest actor rather than the recipient. The resource (
user/{id}) is unchanged. Recovery events already set the event user explicitly, so webhook and realtime payloads are unchanged.Tests
AccountTest::testCreateEmailTokenKeepsCallerIdentity(GraphQL e2e): a guest mutation issues an email token for an existing account and then callsaccountUpdateName. The second field must fail, and the account's name must stay unchanged. Without the fix, the second field succeeds as the recipient.Resolversruns Swoole coroutines, which unit tests must not do. The change removes the per-resolverunset, so the lock object can no longer be replaced during a request.Related: appwrite-labs/cloud#6666