Add Keep-Alive Context Isolation Tests (Issue #29)#31
Merged
Conversation
The v3 action uses Debian Buster which reached EOL and has decommissioned package repositories, causing Docker build failures. Version 4 uses a more recent base image with active repositories. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive unit and e2e tests to verify that HTTP Keep-Alive connections do not leak context data between requests. Unit tests (internal/handler): - Sequential requests on same Keep-Alive connection - Concurrent requests with connection pooling - Raw TCP connection testing - HTTP/1.1 pipelining simulation - Rapid sequential stress testing (1000 requests) - Transport-level RoundTrip isolation E2E tests (tests/e2e): - Sequential requests via curl with Keep-Alive - Concurrent parallel requests - Rapid sequential requests (50 requests) - HTTP/1.1 pipelining with netcat These tests ensure request isolation by verifying that headers from one request (e.g., X-Tenant-Id, X-Correlation-Id) are not leaked to subsequent requests on the same connection, which would be a critical security vulnerability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Description
Adds comprehensive tests to verify that HTTP Keep-Alive connection reuse does not leak request context (headers, propagated data) between different requests on the same TCP connection.
Fixes #29
Problem Statement
HTTP Keep-Alive allows multiple requests to be sent over a single TCP connection. This raises a critical security concern: if the proxy maintains request-specific state in connection-level storage or global variables, one request's context could be visible to subsequent requests on the same connection.
Security Risks:
Solution
Added two comprehensive test suites:
1. Unit Tests (
internal/handler/keepalive_isolation_test.go)Seven unit tests covering:
TestKeepAliveContextIsolation_SequentialRequestsTestKeepAliveContextIsolation_ConcurrentRequestsTestKeepAliveContextIsolation_RawTCPConnectionTestKeepAliveContextIsolation_GlobalStateNotSharedTestKeepAliveContextIsolation_TransportRoundTripHeaderPropagatingTransportdoesn't share stateTestKeepAliveContextIsolation_RapidSequentialTestKeepAliveContextIsolation_HTTP11Pipelining2. E2E Tests (
tests/e2e/keepalive_isolation_test.go)Four Kubernetes e2e tests covering:
Test Results
All tests pass ✅
Why This Matters
The implementation correctly isolates context because:
context.WithValue(r.Context(), ContextKeyHeaders, headerMap)extractHeaders()creates a freshmap[string]stringfor each requestGetHeadersFromContext(req.Context())is request-scoped, not connection-scopedThe tests confirm no context leakage occurs even with Keep-Alive connection reuse.
Changes
internal/handler/keepalive_isolation_test.go(513 lines, 7 tests)tests/e2e/keepalive_isolation_test.go(425 lines, 4 e2e tests)golangci-lint run)Testing Checklist
Security Validation
These tests serve as regression protection to ensure future changes don't introduce context leakage vulnerabilities in Keep-Alive scenarios.