Skip to content

fix: force customerId scope gating in tools and prompt expansions - #66

Open
dylan-klein wants to merge 2 commits into
mainfrom
fix/mcp-client-gating
Open

fix: force customerId scope gating in tools and prompt expansions#66
dylan-klein wants to merge 2 commits into
mainfrom
fix/mcp-client-gating

Conversation

@dylan-klein

@dylan-klein dylan-klein commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

MOTIVATION

In service_account mode, the backend Service Account has broad GCP IAM permissions and can access multiple Workspace domains. Previously, if the administrator manually provided a different customerId in their chat request, the LLM would propagate that parameter down to the tool calls, allowing the admin to query unauthorized tenants. We need to enforce a hard boundary so the agent can only operate within the tenant selected on the UI login screen.

MAIN CHANGES

  • Unconditional Gating: Refactored callMcpTool and getMcpPrompt in src/lib/mcp-client.ts to unconditionally force-overwrite the customerId argument with the active customer ID retrieved from the signed session cookie.
  • Review Fixes: Added fail-fast protection. If resolving the session customerId throws an error (e.g. cookie decryption fails or JWT is tampered), the client now throws a wrapped exception and aborts execution immediately instead of silently swallowing the error and allowing the request to proceed.
  • Safe Fallback: If the session has no active customerId configured, we explicitly delete the client-provided customerId argument to block unauthenticated scope overrides.
  • Test Coverage: Added unit tests in mcp-client.test.ts to cover parameter overwriting, argument stripping, and fail-fast behavior.

DESIGN DECISIONS

  • We chose to perform this gating at the lowest client boundary (mcp-client.ts) rather than in individual tool definitions or route handlers. This provides a centralized bottleneck that protects all current and future tools/prompts from scope bypasses.

TAG=agy
CONV=b3471264-2592-4924-b031-267b4bf62326

TAG=agy
CONV=b3471264-2592-4924-b031-267b4bf62326
- Fail fast and throw a wrapped error if getActiveCustomerId throws an error in callMcpTool and getMcpPrompt, preventing fallback to client-supplied tenant scopes.
- Delete user-supplied customerId if no active session customerId is configured.
- Add unit tests verifying deletion and error throwing for both tools and prompts.

TAG=agy
CONV=b3471264-2592-4924-b031-267b4bf62326
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant