Commit 7a45023
committed
fix(anthropic): bound streaming 200 success-body SSE reads at 16 MiB
Apply createSseByteGuard to src/agents/anthropic-transport-stream.ts so the
Anthropic Messages transport 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
already used for non-streaming Anthropic success bodies.
What changed:
- New helper src/agents/streaming-byte-guard.ts (78 lines, internal core):
createSseByteGuard wraps a ReadableStreamDefaultReader<Uint8Array>,
tracks accumulated bytes across the existing chunk loop, cancels the
underlying reader on overflow, and throws a canonical overflow error.
Internal for now; if extensions need it, promote to a plugin-SDK subpath
in a separate PR with full SDK metadata sync.
- src/agents/anthropic-transport-stream.ts: wrap body.getReader() in
createSseByteGuard before yielding to the existing parseAnthropicSseBody
loop. The readAnthropicSseChunk type was widened to accept any
{ read, cancel } so the same wrapper drives the guarded reader.
- Inline test added to anthropic-transport-stream.test.ts: hostile 1 MiB
pull stream, asserts canonical overflow message in result.errorMessage,
cancel(reason) was an Error instance, pullCount bounded to 17-20.
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
symmetric success-body gap.1 parent 072d3ed commit 7a45023
2 files changed
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2903 | 2903 | | |
2904 | 2904 | | |
2905 | 2905 | | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
2906 | 2949 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
613 | 615 | | |
614 | 616 | | |
615 | 617 | | |
616 | | - | |
| 618 | + | |
617 | 619 | | |
618 | 620 | | |
619 | 621 | | |
| |||
675 | 677 | | |
676 | 678 | | |
677 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
678 | 691 | | |
679 | 692 | | |
680 | 693 | | |
681 | 694 | | |
682 | 695 | | |
683 | | - | |
| 696 | + | |
684 | 697 | | |
685 | 698 | | |
686 | 699 | | |
| |||
0 commit comments