fix(msteams): bound response read in callUserTokenService#98330
fix(msteams): bound response read in callUserTokenService#98330lzyyzznl wants to merge 1 commit into
Conversation
Replace unbounded response.json() with readResponseWithLimit to cap the Bot Framework User Token service response at 16 MB, preventing OOM on oversized responses. Error path was already bounded via readMSTeamsHttpErrorDetail; this aligns the success path with the same defensive pattern used across 50+ provider integrations. Adds 3 new test cases: readResponseWithLimit normal read, overflow rejection, and non-JSON response error handling.
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR targets the same Microsoft Teams SSO success-response read as an earlier open canonical PR, but the canonical PR has the same runtime fix with stronger product-path loopback proof and review context, so keeping this duplicate branch open is not useful. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this duplicate and continue review on #97781, which carries the same Microsoft Teams SSO bounded-read fix with stronger proof. So I’m closing this here and keeping the remaining discussion on #97781. Review detailsBest possible solution: Close this duplicate and continue review on #97781, which carries the same Microsoft Teams SSO bounded-read fix with stronger proof. Do we have a high-confidence way to reproduce the issue? Yes by source inspection. Current main reads the successful User Token service response with bare Is this the best way to solve the issue? No for this branch as the best landing path. The bounded-read approach is correct, but the earlier canonical PR is the better solution because it changes the same owner module and proves the changed SSO handler path with a real loopback HTTP/fetch setup. Security review: Security review cleared: The diff adds no dependency, workflow, package, permission, credential, or secret-handling change and is an availability hardening patch. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 816038e97a5d. |
|
Closing as superseded by #97781 per ClawSweeper review. The same Microsoft Teams SSO bounded-read fix lands in the canonical PR with stronger loopback proof. |
Summary
Problem: The
callUserTokenServicefunction inextensions/msteams/src/sso.tsreads HTTP responses from the Bot Framework User Token service viaresponse.json()with no byte cap. A misconfigured, compromised, or unusually large response body can exhaust gateway heap before the connection timeout fires.Solution: Replace the unbounded
response.json()call withreadResponseWithLimit(response, 16MB)— the project's standard bounded reader exported fromopenclaw/plugin-sdk/response-limit-runtime. On overflow the reader cancels the stream and throws, which is caught by the existing try/catch and returned as a structured error.What changed: Two files modified.
extensions/msteams/src/sso.ts: +1 import (readResponseWithLimit), +1 bounded read replacingresponse.json(). Error path (readMSTeamsHttpErrorDetail) unchanged.extensions/msteams/src/monitor-handler.sso.test.ts: +45 lines adding 3 test cases for bounded-reader integration, overflow rejection, and non-JSON error handling.What did NOT change:
Real behavior proof
Behavior addressed: Replace unbounded
response.json()withreadResponseWithLimitbounded reader incallUserTokenService().Real environment tested: Windows 11 Pro, Node.js v22, OpenClaw gateway.
Exact steps or command run after this patch:
TypeScript compilation and all SSO-related unit tests pass. Bounded reader independently verified:
After-fix evidence:
Observed result after the fix: TypeScript compiles without errors. All 8 tests pass (5 existing + 3 new: bounded reader normal read, overflow rejection, non-JSON error handling). Bounded reader correctly returns small payloads and throws on oversized input.
What was not tested: End-to-end live call against Bot Framework User Token service (requires a deployed Teams bot with AAD app registration and valid SSO channel).
Risk checklist
readResponseWithLimitalready used across the codebase).extensions/msteams/src/sso.ts(+3 lines) and its test file (+45 lines).