Fix CRLF injection in Connection.connect via target_host parameter - #22
Open
cursor[bot] wants to merge 1 commit into
Open
Fix CRLF injection in Connection.connect via target_host parameter#22cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Validate target_host and target_port for CR, LF, and NUL characters before interpolating them into the raw CONNECT request line. This prevents HTTP request smuggling through the proxy when a consuming application passes user-derived input as the connection target. The validation uses the same INVALID_HEADER_VALUE_RE regex already used by validate_header! for proxy header values, ensuring consistency. Validation runs before any network I/O (fail fast). Adds specs covering CR, LF, NUL in target_host and CR in target_port. Co-authored-by: ProxyMesh AI <proxymeshai@users.noreply.github.com>
proxymesh
approved these changes
Aug 6, 2026
proxymesh
marked this pull request as ready for review
August 6, 2026 14:19
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
Fixes a CRLF injection vulnerability in
RubyProxyHeaders::Connection#connectwhere thetarget_hostandtarget_portparameters are interpolated directly into the raw HTTP CONNECT request line without validation for control characters (CR, LF, NUL).Problem
The
build_connect_requestmethod constructs a CONNECT request by directly interpolatingtarget_host:If a consuming application passes user-derived input as the target hostname, an attacker can inject CRLF sequences to smuggle HTTP requests or headers through the proxy.
While
validate_header!was already applied to proxy header values (since v0.2.1), this same validation was missing for the request-line target parameters.Fix
validate_connect_target!private method that checks bothtarget_hostandtarget_portagainstINVALID_HEADER_VALUE_RE(rejects CR, LF, NUL)connect(), before any network I/O (fail fast)Impact
This is a defense-in-depth fix. Exploitation requires a consuming application to pass unsanitized user input directly as a target hostname to
Connection.connect(). The fix ensures the library rejects malicious input regardless of the caller's validation practices.