fix(protect): don't buffer live streams (SSE) in response screening - #108
Merged
Merged
Conversation
Response screening buffers the whole body before deciding, so a Server-Sent-Events / token stream — the common shape for LLM output in AI-built apps — was withheld from the client until the stream *ended* (readTextResponse awaits the reader to `done`). Exclude `text/event-stream` from screening on both paths (the fetch `readTextResponse` and the node `isTextCT` gate): a live stream passes through unbuffered and streams normally, unscreened. This removes the last blocker to enabling response screening by default on streaming stacks. +2 tests (a never-closing SSE stream returns promptly & untouched; a normal text response is still screened); 628 pass; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Adds event-stream checks to skip buffering live SSE responses. 🎯 Quality: 100% Elite · 📦 Size: Small 📈 This month: Your 49th PR — above team average · Averaging Elite |
Contributor
Author
|
/review |
daniloradovic
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Response screening buffers the whole body before deciding (redact/block). For a live stream —
text/event-stream, the standard shape for LLM token streaming, which AI-built apps lean on heavily —readTextResponsereads the body untildone, i.e. until the entire stream ends. So the client sees nothing until generation completes: incremental streaming is broken. Flagged in the output-filtering review as the blocker to enabling response screening by default on Node/Express.What
Exclude
text/event-streamfrom screening on both paths:readTextResponsereturnsnull(skip) for an event-stream →screenResphands back the original response untouched.isTextCTgate returnsfalsefor event-stream → the buffered-response wrapper passes chunks straight through.A live stream now passes through unbuffered and unscreened — the same fail-open tradeoff already used when a body exceeds the screen cap. (Non-stream text responses are screened exactly as before.)
Tests
tests/protect/response-streaming.test.ts— a never-closing SSE stream returns promptly (<500ms) and as the original object (before the fix it would await the stream forever), and a normal text response is still screened. 628 pass; typecheck clean.🤖 Generated with Claude Code