fix(toolsets): prevent x-account-id leak across concurrent fetchTools#367
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency bug in StackOneToolSet.fetchTools() where mutating this.headers around await boundaries could cause tools to be created with the wrong tenant’s x-account-id, enabling cross-account leakage under concurrent calls.
Changes:
- Stop mutating
this.headersduringfetchTools(); instead, build per-request headers and pass them down explicitly. - Thread
requestHeadersthroughfetchToolsFromMcp()→createRpcBackedTool()so tool instances capture the correct account-scoped headers. - Add regressions tests covering intra-call concurrency (
Promise.allover multiple accounts) and inter-call concurrency (twofetchToolscalls on one instance).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/toolsets.ts |
Removes shared mutable header mutation and passes per-request headers through the MCP fetch/tool construction chain. |
src/toolsets.test.ts |
Adds regression tests ensuring tools are stamped with the correct x-account-id under concurrent fetch scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
fetchTools()mutatedthis.headersto inject the per-accountx-account-id, then awaited the MCP fetch. Under concurrencyPromise.allover multipleaccountIds, or twofetchTools()calls on one instance those mutations interleaved.createRpcBackedToolre-readthis.headersafter the await and baked the wrong tenant'sx-account-idinto the returned tools. For a sharedStackOneToolSetserving multiple users, this is a cross-tenant data-leak path.Closes #365
Fix
Stop mutating
this.headers; thread per-request headers through as a parameter intofetchToolsFromMcp→createRpcBackedTool→BaseTool.this.headersis now invariant after construction, so concurrent callers cannot interfere.Mirrors the design already used in the Python SDK (
stackone_ai/toolset.py:_fetch_for_account). ThecatalogCacheis fixed transitively.Test plan
pnpm vitest run src/toolsets.test.ts55/55 pass (53 existing + 2 new)pnpm vitest run559/559 pass, no regressionspnpm lintrun locally in nix dev shellBoth new tests fail deterministically against the buggy code and pass with the fix.
Out of scope
self.headersreferences intoolset.py); no changes needed.fetchToolssignature unchanged.Summary by cubic
Fixes a cross-tenant header leak in concurrent
fetchToolscalls by passing per-requestx-account-idheaders instead of mutating instance headers. Tools now always carry the correct account scope, preventing data leakage in sharedStackOneToolSetinstances.fetchToolsFromMcpand into tool creation;this.headersis no longer mutated.x-account-idunder intra-call and inter-call concurrency.Written for commit e7ed38b. Summary will update on new commits.