Skip to content

fix(openrouter): bound OAuth API key response read in readResponseBody to prevent OOM - #97760

Closed
cxbAsDev wants to merge 1 commit into
openclaw:mainfrom
cxbAsDev:fix/bound-openrouter-oauth-response
Closed

cxbAsDev wants to merge 1 commit into
openclaw:mainfrom
cxbAsDev:fix/bound-openrouter-oauth-response

Conversation

@cxbAsDev

@cxbAsDev cxbAsDev commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The readResponseBody function in the OpenRouter OAuth flow uses await response.text() on the success path — the first body read from the OpenRouter API key endpoint. This is unbounded and can cause OOM on oversized responses. The error path already uses readResponseTextLimited with an 8 KB cap, but the success path was unprotected.

This replaces the success path response.text() with readResponseWithLimit (16 MiB cap), matching the codebase convention.

Evidence

Environment: Linux, Node 22, OpenClaw main @ 0ce10d7

Terminal output — all 9 tests pass, including 1 oversized-response regression test:

$ pnpm test extensions/openrouter/oauth.test.ts --run --reporter=verbose

 ✓ OpenRouter OAuth > builds the documented PKCE authorize URL 22ms
 ✓ OpenRouter OAuth > parses state-bound OpenRouter redirect URLs and query strings 5ms
 ✓ OpenRouter OAuth > exchanges an authorization code for the issued OpenRouter API key 24ms
 ✓ OpenRouter OAuth > surfaces OpenRouter OAuth exchange errors without credential material 3ms
 ✓ OpenRouter OAuth > bounds OpenRouter OAuth exchange error bodies without requiring response.text() 3ms
 ✓ OpenRouter OAuth > stores a browser OAuth result as the default OpenRouter API-key profile 9ms
 ✓ OpenRouter OAuth > uses the local callback path before opening the browser locally 3ms
 ✓ OpenRouter OAuth > exposes stable auth choice metadata 1ms
 ✓ OpenRouter OAuth > rejects oversized OpenRouter OAuth API key responses 42ms

 Test Files  1 passed (1)
      Tests  9 passed (9)

The oversized test provides a fetchImpl mock returning an 18 MiB ReadableStream (cap is 16 MiB) and verifies the bounded reader cancels the stream and the error propagates through exchangeOpenRouterOAuthCode with "OpenRouter OAuth key response exceeds".

Risk

Low. The 16 MiB cap matches the codebase convention. The bounded read replaces the exact same response.text() call on the success path; the error path already uses readResponseTextLimited and is unchanged.

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 29, 2026, 10:50 AM ET / 14:50 UTC.

Summary
The PR replaces the successful OpenRouter OAuth API-key response response.text() read with the shared bounded response reader and adds an oversized-response regression test.

PR surface: Source +7, Tests +38. Total +45 across 2 files.

Reproducibility: yes. from source inspection. Current main and the latest release still call response.text() for successful OpenRouter OAuth key responses, and the PR's injected-stream regression test exercises the same exchangeOpenRouterOAuthCode path, though I did not run a live or loopback repro in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦞 diamond lobster
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Add redacted terminal, log, copied live output, or loopback output showing a normal OpenRouter OAuth API-key response succeeds after the fix.
  • Show an oversized OpenRouter OAuth/API-key response failing at the cap; redact IPs, API keys, phone numbers, non-public endpoints, and other private details.
  • [P1] Coordinate with fix(openrouter,google): bound OAuth response body reads #97745 so one proof-positive OpenRouter success-read fix lands.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body includes unit-test output and a mocked oversized stream, but no redacted real or loopback OpenRouter OAuth/API-key response output after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] External contributor proof is still mock-only: the PR body shows unit tests and an injected stream, but no redacted real or loopback OpenRouter OAuth/API-key response output after the fix.
  • [P1] The success-path cap changes OpenRouter OAuth API-key response handling, so maintainers need normal-size and oversized-response proof or an explicit proof override before merge.
  • [P1] fix(openrouter,google): bound OAuth response body reads #97745 overlaps the same OpenRouter OAuth read, but it is broader and still proof-gated, so maintainers should coordinate which branch owns the OpenRouter change.

Maintainer options:

  1. Require OpenRouter OAuth Proof (recommended)
    Ask for redacted terminal, log, live, or loopback output showing a normal OpenRouter OAuth API-key response still succeeds and an oversized response fails at the cap before merge.
  2. Accept A Proof Override
    Maintainers may intentionally accept the unit and mock-stream evidence for this narrow hardening if real OpenRouter OAuth proof is impractical.
  3. Coordinate The Overlap
    If fix(openrouter,google): bound OAuth response body reads #97745 becomes the preferred proof-positive path, close or narrow one PR so only one OpenRouter success-read change lands.

Next step before merge

  • [P1] The remaining blocker is contributor-supplied real behavior proof or a maintainer proof override plus coordination with the overlapping OpenRouter PR, not a narrow code defect for automation.

Security
Cleared: Cleared: the diff reduces an existing unbounded HTTP response memory exposure and adds no dependency, workflow, secret, package, or code-execution surface.

Review details

Best possible solution:

Land one focused OpenRouter OAuth bounded-reader fix after redacted real or loopback proof shows normal API-key responses still succeed and oversized responses fail at the cap, or after a maintainer explicitly accepts a proof override.

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

Yes from source inspection. Current main and the latest release still call response.text() for successful OpenRouter OAuth key responses, and the PR's injected-stream regression test exercises the same exchangeOpenRouterOAuthCode path, though I did not run a live or loopback repro in this read-only review.

Is this the best way to solve the issue?

Yes for the code shape. Using the existing plugin SDK bounded response helper at the OpenRouter-owned OAuth boundary is the narrowest maintainable fix; merge readiness still depends on real behavior proof or maintainer override and overlap coordination.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR fixes a limited-blast-radius OpenRouter OAuth memory/availability bug without evidence of an urgent active regression.
  • merge-risk: 🚨 auth-provider: The diff changes successful OpenRouter OAuth API-key response handling, so normal auth success and oversized failure behavior need proof before merge.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body includes unit-test output and a mocked oversized stream, but no redacted real or loopback OpenRouter OAuth/API-key response output after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +7, Tests +38. Total +45 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 1 +7
Tests 1 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 46 1 +45

What I checked:

  • Root policy read: Root AGENTS.md was read fully and applied; OpenClaw PR review policy requires provider/auth source, tests, sibling-surface, proof, and dependency-contract checks beyond the diff. (AGENTS.md:1, be94853de0d0)
  • Scoped extension policy read: extensions/AGENTS.md was read fully; the patch stays inside the bundled plugin boundary and imports from openclaw/plugin-sdk/*, which matches the scoped provider-plugin rule. (extensions/AGENTS.md:1, be94853de0d0)
  • Current main bug path: Current main still reads successful OpenRouter OAuth key-exchange responses with await response.text(), while only the error path is bounded. (extensions/openrouter/oauth.ts:76, be94853de0d0)
  • User-facing entry point: loginOpenRouterOAuth calls exchangeOpenRouterOAuthCode, so the read occurs on the OpenRouter OAuth login/API-key exchange path. (extensions/openrouter/oauth.ts:363, be94853de0d0)
  • Latest-release behavior: The latest release tag still shows the same successful-response response.text() read, so the central issue is not already shipped fixed. (extensions/openrouter/oauth.ts:76, aa69b12d0086)
  • PR implementation: The PR head replaces the successful-response response.text() path with readResponseWithLimit using a 16 MiB cap and a specific overflow error. (extensions/openrouter/oauth.ts:77, 30f4f7ffc954)

Likely related people:

  • kenrogers: Authored the OpenRouter OAuth login commit that introduced the touched oauth.ts path later merged through feat: add OpenRouter OAuth to onboarding #91830. (role: original OpenRouter OAuth contributor; confidence: high; commits: b9280d5863cc, b318f35a216e; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts)
  • Patrick-Erichsen: Merged the OpenRouter OAuth onboarding PR and authored the provider-picker follow-up that made the OAuth path visible in setup. (role: feature merger and adjacent owner; confidence: high; commits: b9280d5863cc, dfa22c0a73e7, e9671ed60327; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts, extensions/openrouter/openclaw.plugin.json)
  • vincentkoc: Authored the recent commit bounding OpenRouter OAuth error-body reads in the same function and adjacent tests. (role: recent OpenRouter OAuth hardening contributor; confidence: high; commits: a42a1af942b2; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts)
  • cxbAsDev: Beyond authoring this PR, authored a merged xAI OAuth bounded-response fix using the same helper pattern, making them relevant for this hardening family. (role: adjacent bounded-OAuth contributor; confidence: medium; commits: d5aca1d6d2d7; files: extensions/xai/xai-oauth.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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 29, 2026
@cxbAsDev

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openrouter merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant