Fix: normalize literal \\r\\n escape sequences in HTTP content from MCP clients#58
Open
dhawanmayank wants to merge 1 commit intoPortSwigger:mainfrom
Open
Conversation
… clients MCP clients pass \r\n as literal 4-character text sequences in tool parameters rather than actual CR+LF bytes. The existing normalization in send_http1_request only handled actual CR/LF characters, causing malformed HTTP requests that strict servers (e.g. Apache-Coyote) reject with 400 Bad Request. This commit: - Adds normalizeHttpContent() helper that handles both literal escape sequences and actual line endings - Applies normalization to send_http1_request (replacing the existing incomplete fix) - Applies normalization to create_repeater_tab (previously had no normalization at all) - Applies normalization to send_to_intruder (previously had no normalization at all) Relates to PortSwigger#51
Author
|
@danielgallen This should fix the issues: #51 |
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.
Problem
MCP clients (e.g. Claude Code) pass
\r\nas literal 4-character text escape sequences (\,r,\,n) in JSON tool parameters, rather than actual CR (0x0D) + LF (0x0A) bytes.The existing line-ending normalization in
send_http1_requestonly handles actual CR/LF characters:This doesn't match the literal
\r\ntext, producing malformed HTTP like:...which is a single garbled line instead of properly delimited HTTP.
Strict servers (e.g. Apache-Coyote/Tomcat) reject this with 400 Bad Request, while lenient servers (Cloudflare, nginx) may tolerate it — making the bug intermittent and hard to diagnose.
Additionally,
create_repeater_tabandsend_to_intruderhad no line-ending normalization at all, causing the same issue when requests were sent to Repeater/Intruder tabs.Verification
Confirmed by sending identical raw content via
netcat:\x0D\x0A)\x0A)\r\ntextFix
Added a
normalizeHttpContent()helper that handles both literal escape sequences and actual line endings, converting everything to proper HTTP CRLF:Applied to all three affected tools:
send_http1_request— replaces the existing incomplete normalizationcreate_repeater_tab— previously had no normalizationsend_to_intruder— previously had no normalizationTesting
./gradlew buildsucceeds)demo.testfire.net) — requests now return proper responses instead of 400Relates to #51