Repository navigation
fix(plugin-sdk): bound Copilot token exchange JSON response reads - #97579
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 12:43 PM ET / 16:43 UTC. Summary PR surface: Source +3, Tests +164. Total +167 across 2 files. Reproducibility: yes. Source inspection shows current main still calls unbounded Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the bounded-read hardening after maintainers accept the shared 16 MiB Copilot auth cap and required checks pass on the exact head. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main still calls unbounded Is this the best way to solve the issue? Yes. Reusing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0ad58848b399. Label changesLabel justifications:
Evidence reviewedPR surface: Source +3, Tests +164. Total +167 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
464a901 to
9b050b2
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
a8df049 to
a45e6d3
Compare
a45e6d3 to
5b20f0b
Compare
|
Merge-ready from local maintainer review. Autoreview is clean at head SHA 5b20f0b, CI is green, and I found no compatibility concerns or breaking changes. This is the best narrow fix for the Copilot token exchange JSON parse-boundary gap: it applies the existing 16 MiB provider JSON cap to the owning token response read path while preserving normal Copilot auth behavior. |
…enclaw#97579) * fix(plugin-sdk): bound Copilot token exchange JSON response reads * test(plugin-sdk): add HTTP transport proof for Copilot token bounds * fix(test): cast HTTP transport fetch mocks to typeof fetch --------- Co-authored-by: NIO <[email protected]>
…enclaw#97579) * fix(plugin-sdk): bound Copilot token exchange JSON response reads * test(plugin-sdk): add HTTP transport proof for Copilot token bounds * fix(test): cast HTTP transport fetch mocks to typeof fetch --------- Co-authored-by: NIO <[email protected]> (cherry picked from commit 2f510a0)
What Problem This Solves
Fixes an issue where the GitHub Copilot API token exchange success response
was read with an unbounded
await res.json(), meaning a misbehaving,compromised, or proxied Copilot token endpoint could stream an arbitrarily
large JSON body into the Node.js heap before parsing began — causing memory
pressure or OOM during
openclaw onboardand every Copilot auth refresh.The failure path at
provider-auth.ts:309already callscancelUnreadResponseBody(res)to release the stream, but the success pathimmediately below had no size cap — a clear asymmetric gap.
This is a SDK-level path (
src/plugin-sdk/): every consumer ofresolveCopilotApiToken(agent startup, onboarding, live Copilot inferencesessions) is affected. Sibling paths in the same campaign that have already
been fixed include
github-copilot/usage.tsandgithub-copilot/embeddings.ts(merged #96607), and
github-copilot/login.tsdevice-flow exchange (merged#97583).
Why This Change Was Made
readProviderJsonResponse(from../agents/provider-http-errors.js, the samemodule re-exported via
openclaw/plugin-sdk/provider-http) wrapsreadResponseWithLimitwith a 16 MiB cap, cancels the ReadableStream onoverflow, and wraps JSON parse errors in a consistent
"<label>: malformed JSON response"message.The
parseCopilotTokenResponsewrapper is unchanged — it still validates thetokenandexpires_atfields after the bounded read. Net diff: +1 import,+2 production lines (wrapping the existing single-line call).
User Impact
No user-visible behavior change for well-behaved GitHub Copilot endpoints.
Operators or users whose Copilot token endpoint returns an oversized JSON
payload (e.g., a misconfigured proxy, a MITM relay, or a future protocol
change) will now see a bounded error
(
github-copilot.token: JSON response exceeds 16777216 bytes) instead ofunbounded heap growth.
Changes
src/plugin-sdk/provider-auth.ts:readProviderJsonResponsefrom../agents/provider-http-errors.jsawait res.json()withreadProviderJsonResponse(res, "github-copilot.token")on the Copilot tokenexchange success path
src/plugin-sdk/provider-auth.test.ts:bounds oversized Copilot token success body and cancels the stream(injected
ReadableStreamregression)bounds oversized Copilot token success body over HTTP transport(
node:httpserver + realfetch/undicithroughresolveCopilotApiToken)accepts a normal Copilot token success body over HTTP transport(happy-path HTTP proof)
Rebased onto current
main.Real behavior proof
Behavior addressed: Prevents unbounded JSON parse allocation on the Copilot
token exchange success path. Oversized streamed bodies fail closed with a
labeled error before
JSON.parseruns.Real environment tested: Node v22, macOS 24.3.0,
node:httpstreamingserver on
127.0.0.1, builtresolveCopilotApiTokenfromdist/plugin-sdk/provider-auth.js, realfetch/undici transport (not injectedResponseobjects for path-level cases).Exact steps:
Content-Length).resolveCopilotApiTokenwithfetchImplpointing at the local server→ assert labeled rejection.
write succeeds.
readProviderJsonResponseon the same streamed HTTP body → assertparse cap fires.
response.json()drains 64 MiB withoutcancelling the stream.
provider-authHTTP transport regression tests.Observed result:
github-copilot.token: JSON response exceeds 16777216 bytesproxy-ep=metadata intact; cache write once.json()read all 64 chunks; nocancel()readCount=17,cancel()invokedALL PROOF ASSERTIONS PASSEDWhat was not tested: live
api.github.com/copilot_internal/v2/tokencalls.Evidence
New bound regression tests (3 added):
bounds oversized Copilot token success body and cancels the stream✓bounds oversized Copilot token success body over HTTP transport✓accepts a normal Copilot token success body over HTTP transport✓