Skip to content

Commit 250d1e8

Browse files
LeonidasLuxclaude
andcommitted
fix(msteams): bound User Token service JSON response reads to prevent OOM
Replace unbounded `response.json()` in `callUserTokenService` with `readProviderJsonResponse(response, "msteams.sso-user-token")` — the same shared bounded reader already deployed across the codebase (#95218, #96322, #96495, #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]>
1 parent c0b6b84 commit 250d1e8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

extensions/msteams/src/monitor-handler.sso.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,27 @@ describe("handleSigninTokenExchangeInvoke", () => {
156156
}
157157
expect(calls).toHaveLength(0);
158158
});
159+
160+
it("returns error when User Token service returns malformed JSON", async () => {
161+
const fetchImpl: MSTeamsSsoFetch = async () => {
162+
return new Response("not-valid-json", {
163+
status: 200,
164+
headers: { "content-type": "application/json" },
165+
});
166+
};
167+
const { sso } = createSsoDeps({ fetchImpl });
168+
169+
const result = await handleSigninTokenExchangeInvoke({
170+
value: { id: "flow-1", connectionName: "GraphConnection", token: "exchangeable-token" },
171+
user: { userId: "aad-user-guid", channelId: "msteams" },
172+
deps: sso,
173+
});
174+
175+
expect(result.ok).toBe(false);
176+
if (!result.ok) {
177+
expect(result.message).toContain("invalid JSON from User Token service");
178+
}
179+
});
159180
});
160181

161182
describe("handleSigninVerifyStateInvoke", () => {

extensions/msteams/src/sso.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* that ack; these helpers encapsulate token exchange and persistence.
2525
*/
2626

27+
import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
2728
import type { MSTeamsAccessTokenProvider } from "./attachments/types.js";
2829
import { readMSTeamsHttpErrorDetail } from "./http-error.js";
2930
import type { MSTeamsSsoTokenStore } from "./sso-token-store.js";
@@ -130,7 +131,7 @@ async function callUserTokenService(
130131
}
131132
let parsed: unknown;
132133
try {
133-
parsed = await response.json();
134+
parsed = await readProviderJsonResponse(response, "msteams.sso-user-token");
134135
} catch {
135136
return { error: "invalid JSON from User Token service", status: response.status };
136137
}

0 commit comments

Comments
 (0)