fix: harden org authorization and Prisma scoping with bounded limits - #1600
Open
Outlaw1299 wants to merge 8 commits into
Open
Outlaw1299 wants to merge 8 commits into
Outlaw1299 wants to merge 8 commits into
Conversation
|
@Outlaw1299 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! 🚀 |
Author
|
@Disciplr-Org Hi! This PR is open and ready for review — happy to address any feedback. Thanks! |
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.
Overview
This PR hardens organization authorization and Prisma scoping for the org vault feature. It establishes explicit state, data, authorization, and failure invariants; enforces bounded pagination, polling, chart points, upload sizes, and concurrent requests; prevents redundant fetches and state updates during route changes, reconnects, and rapid user interaction; and exposes structured telemetry for latency, failure, and recovery paths without leaking secrets.
Related Issue
Refs #
Changes
🔒 Organization Authorization & Prisma Scoping
[MODIFY]
src/middleware/orgAuth.ts404for cross-org access to avoid tenant existence leaks.[MODIFY]
src/lib/prismaScope.tsscopedOrgWhereandscopedVaultWherehelpers that always injectorgIdinto Prisma queries.whereoverrides that attempt to remove or replace the required org scope.📏 Explicit Bounds and Limits
[ADD]
src/lib/limits.ts[MODIFY]
src/lib/pagination.tslimitvalues, validate cursors, reject negative/NaN inputs, and enforce stable ordering.[MODIFY]
src/routes/orgVaults.tslimits.tsto query parameters, uploads, and response sizes; return400/413structured errors for violations.[MODIFY]
src/middleware/rateLimit.ts🔄 Redundant Work Prevention
src/routes/orgVaults.ts📡 Telemetry and Diagnostics
[ADD]
src/lib/telemetry.tsorg_auth_denied,org_query_scoped,org_request_latency,org_request_failure, andorg_recovery.[MODIFY]
src/lib/logger.tstelemetrylog level for operational visibility.✅ Tests
[ADD]
src/lib/__tests__/prismaScope.test.tsorgId, retry, and permission-denied behavior.[ADD]
src/middleware/__tests__/orgAuth.test.ts[ADD]
src/routes/__tests__/orgVaults.test.ts429behavior.⚖️ Design Tradeoffs and Limitations
404for unauthorized org access prevents tenant enumeration but can complicate debugging without structured internal error codes.Verification Results
orgIdoverrideslimits.tsenforced and tested in route/middleware coverageRefs #<issue-number>Closes #1546