Improve organization authorization and Prisma scoping: transactional invariants and recovery - #1603
Open
DevALVIN-24 wants to merge 2 commits into
Open
Improve organization authorization and Prisma scoping: transactional invariants and recovery#1603DevALVIN-24 wants to merge 2 commits into
DevALVIN-24 wants to merge 2 commits into
Conversation
…ry pagination in TransactionRepository
…ional invariants and recovery
|
@DevALVIN-24 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #1542
Description
This PR addresses security risks and state management vulnerabilities in organization-scoped queries and mutations by introducing robust tenant isolation boundaries using Prisma client extensions, correcting authorization middleware table lookups, and enforcing deterministic transactional boundaries for saved searches.
Key Changes
Prisma Scoping & Tenant Isolation (
src/lib/prismaScope.ts,src/lib/prisma.ts):PrismaScopewithorgId.$extendsquery extension that intercepts queries on all organization-scoped models (Vault,Team,Membership,AnalyticsReport,AnalyticsReportQuota,OrgVaultSearch).orgIdmatches query parameters, preventing cross-tenant data exposure at the database driver level.Middleware Table Corrections & Scoping (
src/middleware/orgAuth.ts):org_members,team_members) instead ofmemberships.getPrisma()).prismaStorageso it automatically scopes downstream queries.Atomic Operations & Idempotency (
src/routes/orgVaults.ts):MAX_SEARCHES_PER_ORGconstraint inside a database transaction withSerializableisolation level to prevent race conditions during concurrent creations.idempotency-keyrequest headers to prevent duplicate submissions and safely recover state upon transaction failures.Robust Automated Testing (
src/tests/orgVaults.prismaScope.test.ts):Verification Results
Successfully verified all organization authorization, database error handling, and scoping tests:
Output:
Design Tradeoffs & Limitations
/:orgId/vaults/search). However, the compiled SQL is executed directly through the scoped Prisma client (getPrisma().$queryRawUnsafe(...)) to ensure it executes within the active transactional session.