Commit 7c3dea3
committed
fix(anthropic): bound streaming 200 success-body SSE reads at 16 MiB (provider path)
Apply createSseByteGuard to src/llm/providers/anthropic.ts (legacy provider
iterateSseMessages) so the Anthropic Messages provider SSE parser cannot
be exhausted by a hostile or malfunctioning Anthropic-compatible endpoint
that streams an unbounded SSE body. The 16 MiB cap matches the
non-streaming readProviderJsonResponse cap.
What changed:
- src/llm/providers/anthropic.ts: wrap body.getReader() in
createSseByteGuard before the existing iterateSseMessages loop. The
function is also re-exported as iterateSseMessagesForTest for direct
test access.
- Inline test added to anthropic.test.ts: hostile 1 MiB pull stream,
asserts canonical overflow message, cancel(reason) was an Error
instance, pullCount bounded to 17-20.
Reuses the createSseByteGuard helper from src/agents/streaming-byte-guard.ts
(introduced in #96701 for the anthropic-transport-stream path; same
helper, same 16 MiB cap, same overflow-error shape). This PR is the
second of the planned per-surface rescue series for the previously
closed PR #96632, after #96701.
No SDK surface change. No repro script committed (proof in this body).
The companion error-body path is already bounded (readAnthropicMessages
ErrorBodySnippet, 8 KiB + 10s idle timeout, #95108); this PR closes the
legacy-provider success-body gap.1 parent 072d3ed commit 7c3dea3
2 files changed
Lines changed: 59 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
1306 | 1306 | | |
1307 | 1307 | | |
1308 | 1308 | | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
1309 | 1346 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
347 | 349 | | |
348 | 350 | | |
349 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
350 | 363 | | |
351 | 364 | | |
352 | 365 | | |
| |||
357 | 370 | | |
358 | 371 | | |
359 | 372 | | |
360 | | - | |
| 373 | + | |
361 | 374 | | |
362 | 375 | | |
363 | 376 | | |
| |||
1495 | 1508 | | |
1496 | 1509 | | |
1497 | 1510 | | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
0 commit comments