|
| 1 | +// Real behavior proof: MSTeams SSO token exchange bounds the User Token |
| 2 | +// service JSON response so an oversized body cannot OOM the runtime. |
| 3 | +// |
| 4 | +// The proof runs a local HTTP server that returns a User Token response |
| 5 | +// larger than the 64 KiB cap. With the fix the handler rejects with an |
| 6 | +// "invalid JSON" service error; without the bound the runtime would buffer |
| 7 | +// the entire oversized body before parsing. |
| 8 | + |
| 9 | +import { createServer } from "node:http"; |
| 10 | +import type { AddressInfo } from "node:net"; |
| 11 | +import { handleSigninTokenExchangeInvoke } from "../../extensions/msteams/src/sso.js"; |
| 12 | + |
| 13 | +const hugeBody = JSON.stringify({ |
| 14 | + channelId: "msteams", |
| 15 | + connectionName: "GraphConnection", |
| 16 | + token: "delegated-graph-token", |
| 17 | + expiration: "2030-01-01T00:00:00Z", |
| 18 | + padding: "x".repeat(128 * 1024), |
| 19 | +}); |
| 20 | + |
| 21 | +const server = createServer((req, res) => { |
| 22 | + res.writeHead(200, { "Content-Type": "application/json" }); |
| 23 | + res.end(hugeBody); |
| 24 | +}); |
| 25 | + |
| 26 | +await new Promise<void>((resolve, reject) => { |
| 27 | + server.listen(0, "127.0.0.1", () => { |
| 28 | + resolve(); |
| 29 | + }); |
| 30 | + server.on("error", reject); |
| 31 | +}); |
| 32 | +const { port } = server.address() as AddressInfo; |
| 33 | + |
| 34 | +console.log("=== Proof: MSTeams SSO JSON response bound ===\n"); |
| 35 | + |
| 36 | +try { |
| 37 | + const result = await handleSigninTokenExchangeInvoke({ |
| 38 | + value: { id: "flow-1", connectionName: "GraphConnection", token: "exchangeable-token" }, |
| 39 | + user: { userId: "aad-user-guid", channelId: "msteams" }, |
| 40 | + deps: { |
| 41 | + userTokenBaseUrl: `http://127.0.0.1:${port}`, |
| 42 | + connectionName: "GraphConnection", |
| 43 | + tokenProvider: { |
| 44 | + getAccessToken: async () => "bf-service-token", |
| 45 | + }, |
| 46 | + tokenStore: { |
| 47 | + async get() { |
| 48 | + return null; |
| 49 | + }, |
| 50 | + async save() {}, |
| 51 | + async remove() { |
| 52 | + return true; |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }); |
| 57 | + |
| 58 | + if (!result.ok && result.code === "unexpected_response" && /invalid JSON/i.test(result.message)) { |
| 59 | + console.log("PASS: oversized User Token JSON response was rejected without OOM."); |
| 60 | + } else { |
| 61 | + console.log("FAIL: unexpected result:", result); |
| 62 | + process.exitCode = 1; |
| 63 | + } |
| 64 | +} catch (err) { |
| 65 | + console.error("FAIL: handler threw:", err); |
| 66 | + process.exitCode = 1; |
| 67 | +} finally { |
| 68 | + server.close(); |
| 69 | +} |
0 commit comments