Conversation
The eventSource.maxEventSize limit is only checked inside parseLine(), which runs only when a line terminator (CR/LF) is reached. A server can therefore stream a data: field (or any field) that never contains a line terminator; the size check never runs and consumed chunks are never reclaimed, so the client buffers the response body without bound, driving the process toward memory exhaustion. Track the in-progress line length (currentLineSize) and reject the stream once it exceeds maxEventSize plus the longest data: field prefix. This bounds any unterminated line against the configured cap while still accepting a terminated data line whose value is exactly maxEventSize. Adds regression tests for the unterminated-line bypass (stream and E2E) and for the boundary case of a value equal to maxEventSize.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5814 +/- ##
=======================================
Coverage 93.50% 93.50%
=======================================
Files 110 110
Lines 39521 39589 +68
=======================================
+ Hits 36954 37018 +64
- Misses 2567 2571 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
EventSourceStreamonly enforces theeventSource.maxEventSizelimit insideparseLine(), which runs only when a line terminator (CR/LF) is reached. A server can stream a field (e.g.data:) that never contains a line terminator; the size check never runs and consumed chunks are never reclaimed, so the client buffers the response body without bound and can be driven toward memory exhaustion.This change enforces the configured cap during byte accumulation, independent of line framing.
Changes
lib/web/eventsource/eventsource-stream.jscurrentLineSize(bytes of the in-progress line), reset whenever a new line starts (syncLineStartToCursor)._transform(), after each non-terminator byte, throw the existingEventSource message size exceedederror once the line exceedsmaxEventSize + DATA_FIELD_PREFIX_SIZE(the longestdata:prefix:data:+ one space = 6 bytes).data,event,id,retry, comments), not just thedata:branch.maxEventSize <= 0still disables the limit entirely.The
DATA_FIELD_PREFIX_SIZEallowance keeps a terminateddata:line whose value is exactlymaxEventSizeaccepted (e.g.data: 123456789a\n\nwithmaxEventSize: 10).Tests
test/eventsource/eventsource-stream.jsenforces maxEventSize on an unterminated lineaccepts a terminated data line with a value equal to maxEventSizetest/eventsource/eventsource-constructor.jsdispatcher eventSource.maxEventSize closes the connection on an unterminated data lineVerification
eslintclean (pre-commit lint hook passed).Examples
Before: with
maxEventSize: 10, a 20-byte unterminateddata:line staysOPENand buffers every byte without bound.After: the same line fires
EventSource message size exceededand the connection closes, whiledata: 123456789a\n\n(10-byte value, exactlymaxEventSize) still dispatches normally.