Skip to content

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

Closed
cxbAsDev wants to merge 3 commits into
openclaw:mainfrom
cxbAsDev:fix/bound-openrouter-oauth-v2
Closed

cxbAsDev wants to merge 3 commits into
openclaw:mainfrom
cxbAsDev:fix/bound-openrouter-oauth-v2

Conversation

@cxbAsDev

@cxbAsDev cxbAsDev commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

readResponseBody in OpenRouter OAuth calls await response.text() on the API key exchange response without a read limit. An oversized response could buffer arbitrarily large payloads before parsing, risking OOM.

Why This Change Was Made

All external HTTP response reads should use readResponseWithLimit (16 MiB cap). The error path already uses readResponseTextLimited — the success path was the only unbounded read remaining.

User Impact

OpenRouter OAuth API key exchange is now protected against oversized JSON responses. Normal exchanges work identically. Oversized responses fail with a clear error message.

Evidence

Environment: Linux, Node 22, OpenClaw main

Real HTTP server loopback proof (committed test)

The test creates a real http.createServer, stubs fetch to redirect OpenRouter requests to it, and proves the bounded reader cancels the socket mid-flight against a real TCP connection:

 ✓ rejects oversized API key responses through the default fetch path 45ms
 ✓ rejects oversized OAuth responses from a real HTTP server (behavior proof) 209ms

10/10 tests pass

$ pnpm test extensions/openrouter/oauth.test.ts
 Test Files  1 passed (1)
      Tests  10 passed (10)

Risk

Low. 16 MiB cap via readResponseWithLimit is the same helper used across all provider JSON reads. The error path already uses bounded reads. Loopback proof demonstrates real TCP connection cancellation.

🤖 Generated with Claude Code

cxbAsDev and others added 3 commits June 30, 2026 23:27
Replace unbounded response.text() on success path with readResponseWithLimit
(16 MiB cap). Error path already uses readResponseTextLimited. Uses default
fetch path (not injected fetchImpl) in regression test for closer-to-real proof.

Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added extensions: openrouter size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 10:01 AM ET / 14:01 UTC.

Summary
The PR changes OpenRouter OAuth success-response parsing to use a 16 MiB bounded response reader and adds oversized-response regression coverage, including loopback HTTP proof.

PR surface: Source +7, Tests +96. Total +103 across 2 files.

Reproducibility: yes. from source inspection, but not from a locally executed repro in this read-only review. Current main and v2026.6.11 still use unbounded response.text() for successful OpenRouter OAuth key responses, and the PR adds current-head oversized-response coverage.

Review metrics: 1 noteworthy metric.

  • OAuth success response readers changed: 1 OpenRouter reader changed. The PR changes successful API-key exchange body handling, so normal auth success and oversized failure behavior deserve maintainer attention before merge.

Root-cause cluster
Relationship: canonical
Canonical: #98645
Summary: This PR is the strongest current OpenRouter-only bounded-read candidate; older same-author attempts are closed, and the broader open OAuth PR overlaps but is not a safe superseding target because it has a known OpenRouter fallback finding and proof/coordination blockers.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
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:

  • Coordinate with the overlapping broader OAuth PR so one canonical OpenRouter bounded-read path lands.

Risk before merge

  • [P1] Merging intentionally changes successful OpenRouter OAuth API-key response handling to fail closed above the 16 MiB cap, so maintainers should accept that auth-provider contract.
  • [P1] An overlapping broader OAuth PR also edits the OpenRouter reader; maintainers should choose one canonical OpenRouter landing path to avoid duplicate or conflicting hardening work.

Maintainer options:

  1. Land Focused OpenRouter Fix (recommended)
    If maintainers accept the 16 MiB fail-closed OpenRouter OAuth response cap, this branch is the cleaner OpenRouter-specific landing path and the overlapping PR should be narrowed or closed for this surface.
  2. Choose The Broader OAuth Branch
    If maintainers want Google and OpenRouter OAuth hardening landed together, require the broader branch to preserve the OpenRouter fallback and carry current-head proof before superseding this branch.

Next step before merge

  • [P2] The branch has no narrow code defect for automation; maintainers need to choose the canonical landing path against the overlapping OAuth PR.

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

Review details

Best possible solution:

Use this focused branch, or an equivalent narrow patch, as the canonical OpenRouter OAuth bounded-read fix while narrowing or closing the overlapping broader PR's OpenRouter portion.

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

Yes from source inspection, but not from a locally executed repro in this read-only review. Current main and v2026.6.11 still use unbounded response.text() for successful OpenRouter OAuth key responses, and the PR adds current-head oversized-response coverage.

Is this the best way to solve the issue?

Yes for the production code shape. Using the existing shared bounded reader inside the OpenRouter-owned OAuth module is the narrow maintainable fix, and this branch preserves the previous malformed/empty-body fallback that the broader overlapping branch dropped.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a focused OpenRouter OAuth resource-exhaustion hardening fix with limited provider-plugin blast radius and no evidence of an active outage.
  • merge-risk: 🚨 auth-provider: The diff changes successful OpenRouter OAuth API-key response handling and introduces a fail-closed size cap on an auth-provider path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes current-head after-fix terminal output for the OpenRouter OAuth loopback/oversized-response tests, and the live Real behavior proof check succeeded on the current head.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes current-head after-fix terminal output for the OpenRouter OAuth loopback/oversized-response tests, and the live Real behavior proof check succeeded on the current head.
Evidence reviewed

PR surface:

Source +7, Tests +96. Total +103 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 1 +7
Tests 1 98 2 +96
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 106 3 +103

Acceptance criteria:

  • [P1] pnpm test extensions/openrouter/oauth.test.ts.
  • [P1] Review current-head CI for check-lint, check-test-types, and Real behavior proof.

What I checked:

Likely related people:

  • kenrogers: GitHub metadata for the merged OpenRouter OAuth onboarding PR shows this account authored the commit that added extensions/openrouter/oauth.ts and its tests. (role: original OpenRouter OAuth contributor; confidence: high; commits: b318f35a216e; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts)
  • Patrick-Erichsen: GitHub metadata shows this account authored the onboarding picker follow-up and merged the OpenRouter OAuth feature PR that introduced the touched path. (role: feature merger and adjacent owner; confidence: high; commits: b318f35a216e, dfa22c0a73e7; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts, extensions/openrouter/provider-contract-api.ts)
  • Vincent Koc: Recent history shows this author changed the same OpenRouter OAuth reader area to bound error bodies and added adjacent test coverage. (role: recent OpenRouter OAuth hardening contributor; confidence: medium; commits: a42a1af942b2; files: extensions/openrouter/oauth.ts, extensions/openrouter/oauth.test.ts)
  • wm0018: git blame attributes the current success-reader lines to a recent merged context-path PR; the change appears to have carried forward older behavior rather than introduced the original pattern. (role: recent area contributor; confidence: medium; commits: dcc2db1825ea; files: extensions/openrouter/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 proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 1, 2026
@cxbAsDev

cxbAsDev commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by upstream's readProviderJsonResponse bounded read implementation. The core OAuth response bound is now handled by the provider-http helper on main.

@cxbAsDev cxbAsDev closed this Jul 7, 2026
@cxbAsDev
cxbAsDev deleted the fix/bound-openrouter-oauth-v2 branch July 15, 2026 03:32
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant