Reject backslash in URL authority per RFC 3986#1659
Open
rodrigobnogueira wants to merge 4 commits intoaio-libs:masterfrom
Open
Reject backslash in URL authority per RFC 3986#1659rodrigobnogueira wants to merge 4 commits intoaio-libs:masterfrom
rodrigobnogueira wants to merge 4 commits intoaio-libs:masterfrom
Conversation
Backslashes are not valid in the authority component per RFC 3986. WHATWG parsers treat them as forward slashes, creating parsing inconsistencies that enable SSRF attacks when yarl is used alongside WHATWG-compliant parsers. Example SSRF vector: http://example.com\@evil.com - WHATWG preprocessor parses host=example.com (trusted) - yarl parses host=evil.com (attacker-controlled) because \ is kept in netloc and @ triggers userinfo splitting Fix: raise ValueError for any URL where the authority contains a backslash.
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (97.64%) is below the target coverage (100.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #1659 +/- ##
=======================================
Coverage 99.47% 99.48%
=======================================
Files 30 30
Lines 5942 5975 +33
Branches 283 285 +2
=======================================
+ Hits 5911 5944 +33
Misses 22 22
Partials 9 9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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.
What do these changes do?
Reject URLs whose authority (netloc) component contains a backslash (
\), which is not a valid character in the authority per RFC 3986. Previously, yarl silently accepted these URLs and treated the backslash as part of the host, producing unexpected parsed results.This aligns yarl's parsing with the RFC 3986 grammar where
\is not listed among valid authority characters (unreserved / pct-encoded / sub-delims / ":" / "@").Are there changes in behavior for the user?
Yes.
URL(r"http://example.com\path")now raisesValueErrorinstead of silently producing a misleading parsed result where the backslash becomes part of the host.Is it a substantial burden for the maintainers to support this?
No. It is a single guard in
split_url()in_parse.py, with four parametrized test cases.Related issue number
N/A
Checklist
CHANGES/folder