Skip to content

Fix/bound copilot login json responses - #97583

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
hugenshen:fix/bound-copilot-login-json-responses
Jun 29, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
hugenshen:fix/bound-copilot-login-json-responses

Conversation

@hugenshen

Copy link
Copy Markdown
Contributor

fix(github-copilot): bound device-flow JSON response reads

What Problem This Solves

postGitHubDeviceFlowForm in extensions/github-copilot/login.ts calls
await response.json() on success responses from both the device-code URL and
the access-token polling URL without any byte limit. An attacker who can intercept
or spoof the GitHub endpoint (MITM, DNS poisoning, or operator-misconfigured proxy)
could return an arbitrarily large JSON body and exhaust Node.js heap memory.

The fix is XS: one import line, two lines at the call site.

Why This Change Was Made

readProviderJsonResponse (from openclaw/plugin-sdk/provider-http) caps JSON reads
at 16 MiB, cancels the underlying ReadableStream on overflow, and surfaces a
provider-tagged error. The same helper is already used in
extensions/github-copilot/usage.ts and embeddings.ts within the same extension —
no new dependency surface is added.

The non-OK branch (!response.ok) already throws before reading the body; only the
success-body read at line 151 was unbounded.

User Impact

  • Normal path: no change — valid GitHub device code and access token responses
    are well under 1 KiB. The full normal flow (device code → authorization → token)
    passes the regression suite unchanged.
  • Oversized / malicious response: instead of OOM, the process now throws a
    ProviderHttpError("github-copilot.device-flow: JSON response exceeds 16777216 bytes").

Evidence

Unit tests — extensions/github-copilot/login.test.ts (new file, 7 tests)

✓  runGitHubCopilotDeviceFlow — normal flow
   ✓ returns authorized status and access token on successful flow          22ms
   ✓ returns access_denied when GitHub rejects the authorization             2ms
   ✓ returns expired when GitHub reports expired_token                       1ms
✓  runGitHubCopilotDeviceFlow — HTTP error propagation
   ✓ throws with failureLabel on non-OK device code response                 1ms
   ✓ throws with failureLabel on non-OK access token response                2ms
✓  postGitHubDeviceFlowForm — response size bound
   ✓ bounds oversized device code body and cancels the stream                8ms
   ✓ bounds oversized access token body and cancels the stream               9ms

 Test Files  1 passed (1)
      Tests  7 passed (7)
   Duration  1.98s

Tests use setGitHubCopilotDeviceFlowFetchGuardForTesting (the existing test seam)
to inject real Response objects without mocking any modules. Coverage:

Scenario Asserts
Full happy path { status: "authorized", accessToken }, showCode called with correct args, exactly 2 network calls
access_denied { status: "access_denied" }
expired_token { status: "expired" }
Device code HTTP 401 throws "GitHub device code failed: HTTP 401"
Token poll HTTP 500 throws "GitHub device token failed: HTTP 500"
Oversized device code body throws "github-copilot.device-flow", readCount < 64, canceled === true
Oversized access token body throws "github-copilot.device-flow", readCount < 64, canceled === true

Real-network proof (node scripts/proof-copilot-login-bound.mjs)

HTTP status: 200
Threw: github-copilot.device-flow: JSON response exceeds 16777216 bytes
Server sent: ~17.0 MiB of 64 MiB total
PASS: stream cancelled after ~17.0 MiB (cap ~16 MiB, not 64 MiB)

A local node:http server streams 64 MiB. The client read ~17 MiB (cap + TCP
buffer) before cancelling; the remaining ~47 MiB was never transferred.

Files changed

File Change
extensions/github-copilot/login.ts import readProviderJsonResponse; replace await response.json()
extensions/github-copilot/login.test.ts new file — 7 tests covering full device flow, HTTP errors, and both oversized-body paths

@clawsweeper

clawsweeper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 29, 2026, 12:52 AM ET / 04:52 UTC.

Summary
The PR changes GitHub Copilot device-flow login success JSON parsing to use the shared bounded provider JSON reader and adds regression tests for normal, error, and oversized-body paths.

PR surface: Source +3, Tests +205. Total +208 across 2 files.

Reproducibility: yes. Current main and v2026.6.10 call native response.json() in postGitHubDeviceFlowForm, and the existing fetch-guard test seam can inject an oversized success Response on either device-flow call path.

Review metrics: 1 noteworthy metric.

  • Capped login response paths: 2 success-body paths covered by 1 shared helper. The changed helper is used by both device-code creation and access-token polling, so the auth compatibility impact applies to both responses.

Stored data model
Persistent data-model change detected: serialized state: extensions/github-copilot/login.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #97583
Summary: This PR is the canonical open fix for GitHub Copilot plugin device-flow login success-body reads; related items cover sibling bounded-read call sites.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Let the pending required checks finish and confirm any failures are unrelated or fixed.
  • [P1] Have a maintainer explicitly accept the 16 MiB fail-closed behavior for Copilot login success responses.

Risk before merge

  • [P1] Oversized GitHub Copilot device-code and token-poll success responses that previously flowed into native parsing now fail closed at the shared 16 MiB provider JSON cap, so maintainers should accept that auth compatibility boundary before merge.
  • [P1] Several broad PR checks were still pending at review time; required checks should finish green or be explained before landing.

Maintainer options:

  1. Accept the shared login cap after checks (recommended)
    Keep this implementation and explicitly accept that oversized Copilot device-flow success bodies now fail at the shared 16 MiB provider JSON cap once CI settles.
  2. Tune the auth failure boundary first
    If maintainers want a different threshold or error shape for this login flow, adjust the bounded-reader policy or call-site label before merge.
  3. Pause for broader Copilot auth policy
    Pause or close only if maintainers decide Copilot login should not use the shared provider JSON response cap yet.

Next step before merge

  • No automated repair is identified; the remaining action is maintainer acceptance of the auth-provider compatibility boundary plus normal CI validation.

Security
Cleared: Cleared: the diff hardens an external auth response read and does not change dependencies, workflows, lockfiles, secrets, permissions, or package resolution.

Review details

Best possible solution:

Land this bounded-reader change after required checks settle and maintainers accept the shared 16 MiB Copilot login cap, while keeping the separate SDK token-exchange work in #97579.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main and v2026.6.10 call native response.json() in postGitHubDeviceFlowForm, and the existing fetch-guard test seam can inject an oversized success Response on either device-flow call path.

Is this the best way to solve the issue?

Yes. Reusing the existing plugin-sdk readProviderJsonResponse facade is the narrowest maintainable owner-boundary fix and matches sibling Copilot usage and embeddings hardening.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 75db48a17522.

Label changes

Label justifications:

  • P2: This is normal-priority GitHub Copilot auth hardening with limited runtime blast radius and no new product surface.
  • merge-risk: 🚨 compatibility: The PR changes oversized success responses from native parsing behavior to a hard 16 MiB labeled failure.
  • merge-risk: 🚨 auth-provider: The changed helper is in the GitHub Copilot device-flow exchange used to obtain credentials.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Sufficient: the PR body includes after-fix live terminal output from a local HTTP server streaming an oversized response through the changed login path and observing bounded failure plus stream cancellation.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient: the PR body includes after-fix live terminal output from a local HTTP server streaming an oversized response through the changed login path and observing bounded failure plus stream cancellation.
Evidence reviewed

PR surface:

Source +3, Tests +205. Total +208 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 205 0 +205
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 209 1 +208

What I checked:

Likely related people:

  • hugenshen: Authored the merged sibling GitHub Copilot model discovery and embeddings bounded-read PR and also owns this open device-flow proposal. (role: recent adjacent contributor; confidence: high; commits: 1aa7cafc35a1, b93af650a402; files: extensions/github-copilot/embeddings.ts, extensions/github-copilot/embeddings.test.ts, extensions/github-copilot/login.ts)
  • Alix-007: Authored the merged GitHub Copilot usage response-read hardening using the same readProviderJsonResponse pattern. (role: shared bounded-reader contributor; confidence: high; commits: 646e54ae3578; files: extensions/github-copilot/usage.ts, extensions/github-copilot/models.test.ts)
  • wangmiao0668000666: Authored the merged core GitHub Copilot OAuth bounded-read PR in the same auth-provider hardening campaign. (role: adjacent auth-provider contributor; confidence: medium; commits: bd0c052aa5e1; files: src/llm/utils/oauth/github-copilot.ts, src/llm/utils/oauth/github-copilot.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jun 28, 2026
@harjothkhara

Copy link
Copy Markdown
Contributor

I checked the current red CI on b1d3772e333c3c713a48599893d8ba2782fe0e8f. The PR-local blocker I see is lint-only in the new test file:

  • check-lint and check-additional-extension-bundled both report eslint(curly) Expected { after 'if' condition at extensions/github-copilot/login.test.ts:69, :83, :107, and :163. Those are the four one-line if (callIdx === 1) return guardResponse(...) branches; adding braces around those returns should clear the branch-local lint errors.

The other red traces I checked look outside this PR's Copilot login surface: check-test-types fails in src/agents/embedded-agent-runner/run/payloads.test.ts / src/agents/embedded-agent-utils.test.ts, checks-node-compact-small-1 fails in src/commands/status.summary.runtime.normalization.test.ts, and checks-node-compact-small-whole-2 fails in test/scripts/plugin-sdk-surface-report.test.ts. The lint jobs also include an unrelated extensions/telegram/src/reasoning-lane-coordinator.ts:97 error. So the actionable author-side fix here appears to be the four curly lint spots in login.test.ts; the remaining red jobs likely need maintainer-side baseline/rerun handling if they persist after that.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 28, 2026
@hugenshen
hugenshen force-pushed the fix/bound-copilot-login-json-responses branch from b1d3772 to a54b999 Compare June 28, 2026 23:32
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 28, 2026
@hugenshen
hugenshen force-pushed the fix/bound-copilot-login-json-responses branch from a54b999 to 266d2b1 Compare June 29, 2026 00:43
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jun 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 29, 2026
@vincentkoc
vincentkoc force-pushed the fix/bound-copilot-login-json-responses branch from 266d2b1 to 2716ebc Compare June 29, 2026 04:35
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Jun 29, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 29, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Jun 29, 2026
@vincentkoc
vincentkoc force-pushed the fix/bound-copilot-login-json-responses branch from 2716ebc to b93af65 Compare June 29, 2026 04:45
@vincentkoc
vincentkoc merged commit 748bea3 into openclaw:main Jun 29, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: github-copilot merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants