Skip to content

Fix mock server TCP segment splitting vulnerability#113

Merged
SeanTAllen merged 1 commit intomainfrom
fix-mock-server-tcp-splitting
Feb 13, 2026
Merged

Fix mock server TCP segment splitting vulnerability#113
SeanTAllen merged 1 commit intomainfrom
fix-mock-server-tcp-splitting

Conversation

@SeanTAllen
Copy link
Member

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.

Introduces _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.

Closes #111

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
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2026
@SeanTAllen SeanTAllen merged commit af52a17 into main Feb 13, 2026
10 checks passed
@SeanTAllen SeanTAllen deleted the fix-mock-server-tcp-splitting branch February 13, 2026 02:38
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mock server tests use _received_count which is vulnerable to TCP segment splitting

2 participants