http: parse request URLs with urlsplit - #5140
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5140 +/- ##
=======================================
Coverage 80.63% 80.64%
=======================================
Files 390 390
Lines 96936 96945 +9
=======================================
+ Hits 78168 78177 +9
Misses 18768 18768
🚀 New features to boost your workflow:
|
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.
HTTP_Client.request()takes a full URL and works out where to connect. It does that with a regularexpression at
scapy/layers/http.py:878-900:That expression is not anchored at the end and does not implement URL authority parsing. A URL may
carry user information before the host, separated by
@, and a standard parser knows the realdestination is what follows the
@. This expression takes the firsthost:port-looking run itfinds, which for
http://example.com:80@evil.test/is the user-information part.So a program that validates an attacker-supplied URL with
urllib.parse— deciding the host isallowed — and then hands the same string to Scapy can end up connecting somewhere its check
excluded.
The change uses the standard parser:
urlsplitalso gives the path and query separately, so the request target is built from those anda fragment is excluded, which is what an HTTP client should send. URLs carrying user information
stay valid; they now connect to their authority. Malformed ports and unsupported schemes are
rejected rather than silently mis-parsed.
The added regression asserts that a URL whose user information looks like a host and port connects
to the authority, and that a fragment does not reach the request line. Without the source change it
fails.
Performance was measured on one computer, before and after the fix: a request took 37.4 µs before
and 37.2 µs after. Repeat runs moved by about 2%, so that difference is smaller than the test can
distinguish.