Fix mock server TCP segment splitting vulnerability#113
Merged
SeanTAllen merged 1 commit intomainfrom Feb 13, 2026
Merged
Conversation
Mock servers used `_received_count` or boolean flags with direct data inspection to determine protocol phase, but `_on_received` fires per TCP segment, not per protocol message. If a message split across segments, the server would respond in the wrong phase — causing intermittent test failures like the observed CopyIn/Abort flake. Introduce `_MockMessageReader` that buffers TCP data and extracts complete PostgreSQL frontend messages before processing. Two methods handle the two wire formats: `read_startup_message()` for startup-format messages (StartupMessage, SSLRequest, CancelRequest) and `read_message()` for standard-format messages (Query, SASLInitialResponse, CopyData, etc.). All 13 mock servers that inspect incoming data are converted to the buffered reader pattern. Six stateless/fire-and-forget servers are unchanged. The common pattern: `_on_received` appends to the reader and calls `_process()`, which loops extracting complete messages and dispatching by state. Closes #111
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.
Mock servers used
_received_countor boolean flags with direct data inspection to determine protocol phase, but_on_receivedfires per TCP segment, not per protocol message. If a message split across segments, the server would respond in the wrong phase — causing intermittent test failures like the observed CopyIn/Abort flake.Introduces
_MockMessageReaderthat buffers TCP data and extracts complete PostgreSQL frontend messages before processing. Two methods handle the two wire formats:read_startup_message()for startup-format messages (StartupMessage, SSLRequest, CancelRequest) andread_message()for standard-format messages (Query, SASLInitialResponse, CopyData, etc.).All 13 mock servers that inspect incoming data are converted to the buffered reader pattern. Six stateless/fire-and-forget servers are unchanged.
Closes #111