fix: replace DB-based auth with JWT identity in queries#404
Conversation
📝 WalkthroughWalkthroughThis PR refactors authentication handling across Convex query and mutation handlers by introducing a centralized Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
services/platform/convex/approvals/queries.ts (1)
44-66:⚠️ Potential issue | 🟠 MajorThread ownership must be validated in approval queries.
The three thread-scoped approval queries (
getPendingIntegrationApprovalsForThread,getWorkflowCreationApprovalsForThread,getHumanInputRequestsForThread) authenticate the user but do not verify thread ownership. An authenticated user can call these queries with an arbitrarythreadIdand retrieve approvals for another user's thread, bypassing intended access boundaries.The approvals table has
organizationIdand the codebase defines RLS rules for organization-scoped access control (rls_rules.ts:385-399), but these queries use standardquery()instead ofqueryWithRLS(), which disables RLS enforcement. Either:
- Switch to
queryWithRLS()to leverage existing RLS rules, or- Manually fetch the thread, validate ownership/organization, and validate organization membership before querying approvals—consistent with the pattern in
submitHumanInputResponse.
ab93d61 to
a89c0f3
Compare
…meouts Queries using authComponent.getAuthUser() perform 2 cross-component DB queries (session + user lookup) that consume 800-1000ms on cold starts, exceeding the 1s Convex query limit and triggering error pages. Replace with ctx.auth.getUserIdentity() which reads from the already-validated JWT with 0 DB queries. Organization membership checks via getOrganizationMember() are preserved. Mutations remain unchanged with full DB session validation.
a89c0f3 to
3cf1ad4
Compare
Summary
authComponent.getAuthUser()perform 2 cross-component DB queries (session + user lookup) that consume 800-1000ms on cold starts, exceeding the 1s Convex query limit and triggering full error pages on the client (GlitchTip: TALE-PROJECT-A, TALE-PROJECT-L)getAuthUserIdentity()helper that usesctx.auth.getUserIdentity()— reads from the already-validated JWT with 0 DB queries instead of 2authComponent.getAuthUser()withgetAuthUserIdentity()across all 13 query files (27 handlers total)getOrganizationMember()are preserved — access control still enforced via DBauthComponent.getAuthUser()Before vs After (per query call)
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor