fix(auth): cancel CIMD response body on early-return paths - #354
Merged
punkpeye merged 3 commits intoSep 4, 2026
Conversation
resolveCimdClient() left the fetch response body unconsumed on two early returns: the non-2xx branch and readBoundedText's Content-Length cap. Node does not free the socket behind a fetch response until its body is consumed or cancelled, so a client_id pointing at a server that answers non-2xx or advertises an oversized Content-Length stranded one connection per request. Await cancelResponseBody(response) before each early return, matching the existing convention at DiscoveryDocumentCache and FastMCP.
|
🎉 This PR is included in version 4.19.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
src/auth/utils/cimd.tsleaked thefetchresponse body on two early-return paths — it was the only fetch site in the repo not callingcancelResponseBody, and didn't import it:if (!response.ok) { return null; }— returned without consuming/cancellingresponse.body.readBoundedTextif (contentLength && Number(contentLength) > CIMD_MAX_RESPONSE_BYTES) { return null; }— returned before the body reader is created; body never cancelled.Per
src/cancelResponseBody.ts, Node won't free the socket until the body is consumed/cancelled, so a stream of failing CIMD lookups (reachable from the OAuth token/authorize endpoints viaresolveCimdClient()for an HTTPSclient_id, SEP-991) strands one socket each. Every other fetch site already guards this way (DiscoveryDocumentCache.ts,FastMCP.tsimageContent/audioContent).Fix:
await cancelResponseBody(response)before each earlyreturn null, matching the sibling convention.Tests
Two tests in
cimd.test.tswith aReadableStreambody whosecancel()sets a flag: a non-2xx response and an over-Content-Lengthresponse both assertresolveCimdClientreturnsnullandbody.cancelwas called. RED before, GREEN after. Full auth suite 315 pass;tsc/prettier clean.