fix(msteams): bound User Token service JSON response reads to prevent OOM#101585
fix(msteams): bound User Token service JSON response reads to prevent OOM#101585LeonidasLux wants to merge 1 commit into
Conversation
… OOM Replace unbounded `response.json()` in `callUserTokenService` with `readProviderJsonResponse(response, "msteams.sso-user-token")` — the same shared bounded reader already deployed across the codebase (openclaw#95218, openclaw#96322, openclaw#96495, openclaw#96889). Enforces a 16 MiB default cap and cancels the underlying stream on overflow. Closes the last unbounded JSON read on the MSTeams SSO token-exchange path. Error responses were already bounded via `extractProviderErrorDetail`. Co-Authored-By: Claude <[email protected]>
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this helper-level branch overlaps the same Microsoft Teams SSO User Token JSON-read hardening already owned by the open, proof-positive route-level PR that covers the live registered sign-in paths. 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 as the canonical route-level Microsoft Teams SSO bounded-read fix. 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 as the canonical route-level Microsoft Teams SSO bounded-read fix. Do we have a high-confidence way to reproduce the issue? Yes, from source inspection: current main still has raw Is this the best way to solve the issue? No for this branch as the best landing path. The helper swap is plausible, but #97781 covers the same helper plus the live registered route boundary and sovereign-cloud parity with stronger proof. Security review: Security review cleared: The diff narrows an external JSON response-read boundary and adds no dependencies, scripts, workflow changes, permissions, package-resolution changes, or secret handling. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 2ba622ca3019. |
|
🦞✅ Reason: structured ClawSweeper close marker: close-required (sha=250d1e826fb68c7024d37f207b354a38711e24b4) Closed:
|
Related: #95218, #96322, #96495, #96889
What Problem This Solves
Fixes an issue where the MSTeams SSO
callUserTokenServicepath usesunbounded
response.json()to parse the Bot Framework User Tokenservice authorization success body. A misbehaving, compromised, or
self-hosted User Token service endpoint can stream an arbitrarily
large JSON response, causing the gateway process to buffer it all
into memory — leading to memory pressure or OOM on the Teams SSO
token-exchange path.
The shared bounded JSON reader (#95218) already covers the main
provider pipeline, image generation (#96495), video generation
(#96889), and the MiniMax OAuth path (#96322). The MSTeams SSO User
Token service call was missed in those rounds and is closed here.
Why This Change Was Made
Replace
response.json()withreadProviderJsonResponse(response, "msteams.sso-user-token")—the same shared helper already used across the codebase. This
enforces a 16 MiB default cap and, on overflow, cancels the
underlying stream and throws a bounded error
(
msteams.sso-user-token: JSON response exceeds 16777216 bytes).Malformed-JSON error messages are preserved for backward
compatibility.
No new abstraction — reuses the existing
plugin-sdkbounded reader.The error-response path (
readMSTeamsHttpErrorDetail) already usedthe bounded
extractProviderErrorDetailhelper and is unchanged.User Impact
No user-visible impact for normal operation. Operators who configure
MSTeams SSO against a self-hosted or proxied User Token service
endpoint are now protected against oversized authorization responses
instead of silently buffering them unbounded.
Evidence
Unit tests
The in-repo Vitest suite for the MSTeams SSO handler passes in full
(6/6), covering the happy path, HTTP service errors, missing-user
rejection, and the new malformed-JSON error path.
Error response path already bounded
readMSTeamsHttpErrorDetail(called on non-OK responses) delegatesto
extractProviderErrorDetailfromplugin-sdk/provider-http,which uses the same bounded reader.
L2 — Real behavior proof: oversized JSON capped at 16 MiB
A proof script (
evidence/pr-101585/oversized-json-proof.ts) exercisesthe exact
readProviderJsonResponsecall used in this fix with a16.96 MiB JSON payload (well over the 16 MiB
PROVIDER_JSON_RESPONSE_MAX_BYTESdefault) to confirm the bounded reader cancels the stream before
buffering the full response.
Result: After this fix, an oversized User Token service JSON response
is detected at 16 MiB and the underlying stream is cancelled immediately
(7.1 ms). Before this fix,
response.json()would buffer the entireuntrusted payload uncontested (51.9 ms for 16.96 MiB; no upper bound).
What was not tested
endpoint (requires AAD app registration and Teams client context).
handleSigninVerifyStateInvokepath — it calls the samecallUserTokenServicehelper and is covered by the samereadProviderJsonResponseswap; the regression test focuses onhandleSigninTokenExchangeInvokeas the more exercised code path.AI-assisted.