fix: partition server-side caches by customerId to prevent leakage - #65
Open
dylan-klein wants to merge 2 commits into
Open
fix: partition server-side caches by customerId to prevent leakage#65dylan-klein wants to merge 2 commits into
dylan-klein wants to merge 2 commits into
Conversation
- Export and reuse CUSTOMER_ID_REGEX in constants.ts and env.ts. - Validate customerId format in sa-config POST API route and add a test case. - Move getActiveCustomerId and callerKey inside try/catch blocks in API routes to prevent uncaught 500 crashes. TAG=agy CONV=b3471264-2592-4924-b031-267b4bf62326
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.
MOTIVATION
In
service_accountmode, multiple administrators from different tenants share the same global Service Account credentials and thus generate the same OAuth access token. Because server-side caches (MCP tools, prompts, users, and risky activity) previously keyed their data using only the token hash, this caused cross-tenant cache collisions. For example, Admin B (Tenant B) could query the same endpoint and receive cached directory data or activity logs belonging to Admin A (Tenant A), representing a critical data leakage vulnerability.MAIN CHANGES
buildCallerCacheKeyinsrc/lib/cache-key.tsto accept an optionalcustomerIdparameter and append|c:<customerId>to the resulting cache key string./api/users,/api/tools,/api/prompts,/api/insights/risky-activity) and internal fetch helpers (activity-data.ts,mcp-tools.ts) to retrieve the activecustomerIdfrom the session and pass it to the cache key builder.tryblocks to prevent unhandled 500 crashes on corrupted cookies.cache-key.test.tsand next/headers mocks in integration tests to support the session validation flow.DESIGN DECISIONS
TAG=agy
CONV=b3471264-2592-4924-b031-267b4bf62326