-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CVE-2021-23336] urllib.parse.parse_qsl(): Web cache poisoning - ;
as a query args separator
#87133
Comments
The urlparse module treats semicolon as a separator (https://github.com/python/cpython/blob/master/Lib/urllib/parse.py#L739) - whereas most proxies today only take ampersands as separators. Link to a blog post explaining this vulnerability: https://snyk.io/blog/cache-poisoning-in-popular-open-source-packages/ When the attacker can separate query parameters using a semicolon (;), they can cause a difference in the interpretation of the request between the proxy (running with default configuration) and the server. This can result in malicious requests being cached as completely safe ones, as the proxy would usually not see the semicolon as a separator, and therefore would not include it in a cache key of an unkeyed parameter - such as
urlparse sees 3 parameters here: A possible solution could be to allow developers to specify a separator, like werkzeug does: |
Oops, I missed this issue. I just marked my bpo-42975 issue as a duplicate of this one. My message: urllib.parse.parse_qsl() uses "&" *and* ";" as separators: >>> urllib.parse.parse_qsl("a=1&b=2&c=3")
[('a', '1'), ('b', '2'), ('c', '3')]
>>> urllib.parse.parse_qsl("a=1&b=2;c=3")
[('a', '1'), ('b', '2'), ('c', '3')] But the W3C standards evolved and now suggest against considering semicolon (";") as a separator: https://www.w3.org/TR/2014/REC-html5-20141028/forms.html#url-encoded-form-data "This form data set encoding is in many ways an aberrant monstrosity, the result of many years of implementation accidents and compromises leading to a set of requirements necessary for interoperability, but in no way representing good design practices. In particular, readers are cautioned to pay close attention to the twisted details involving repeated (and in some cases nested) conversions between character encodings and byte sequences." "To decode application/x-www-form-urlencoded payloads (...) Let strings be the result of strictly splitting the string payload on U+0026 AMPERSAND characters (&)." Maybe we should even go further in Python 3.10 and only split at "&" by default, but let the caller to opt-in for ";" separator as well. |
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
On 20.01.2021 12:07, STINNER Victor wrote:
+1. Personally, I've never seen URLs encoded with ";" as query parameter The use of ";" was recommended in the HTML4 spec, but only in an https://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2 and not in the main reference: https://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4.1 Browsers are also pretty relaxed about seeing non-escaped ampersands in |
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
;
as a query args separator;
as a query args separator
Sorry for the title mess: It seems that when replying to a ticket, RoundUp uses the subject line as the new header regardless of what it was set to before. |
Yeah, it's annoying :-( I like to put a module name in the issue title, to help bug triage. |
It looks to me, that this is an issue of proxies, not Python. Python implementation obeys contemporary standards, and they are not formally cancelled yet. If we add an option in parse_qsl() or change its default behavior, it should be considered as a new feature which helps to mitigate proxies' issues. |
The contemporary standard is HTML5 and HTML5 asks to only split at "&", no? |
FWIW, a surprising amount of things rely on treating ';' as a valid separator in the standard test suite. From just a cursory look: test_cgi A change in the public API of urlparse will also require a change in cgi.py's FieldStorage, FieldStorage.read_multi, parse and parse_multipart to expose that parameter since those functions forward arguments directly to urllib.parse.parse_qs internally. If we backport this, it seems that we will *also* need to backport all those changes to cgi's public API. Otherwise, just backporting the security fix part without allowing the user to switch would break existing code. Just my 2 cents on the issue. I'm not too familiar with security fixes in cpython anyways ;). |
Did you upstream fixes for those packages? Asking because if this is considered a vulnerability in Python, it should be considered a vulnerability for every other tool/library that accept Again, I feel like we are blaming the wrong piece of the stack, unless proxies are usually ignoring some arguments (e.g. utm_*) as part of the cache key, by default or in a very easy way. |
Riccardo - FWIW I agree, the wrong part of the stack was blamed and a CVE was wrongly sought for against CPython on this one. It's sewage under the bridge at this point. The API change has shipped in several different stable releases and thus is something virtually Python all code must now deal with. Why was this a bad change to make? Python's parse_qsl obeyed the prevailing HTML 4 standard at the time it was written: https://www.w3.org/TR/html401/appendix/notes.html#ampersands-in-uris ''' That turns out to have been bad advice in the standard. 15 years later the html5 standard quoted in Adam's snyk blog post links to its text on this which leaves no room for that interpretation. In that light, the correct thing to do for this issue would be to:
Afterall, the existence of html5 didn't magically fix all of the html and web applications written in the two decades of web that came before it. Ask any browser author... |
There's another part of the new implementation that looks a bit fishy: the |
Petr, On
No, this was not intentional. The separator arg was just coice, for compatibility, if some wanted to use |
Of course we did. Upstream first! |
erlandaasland you’ve been editing closed issues today (got messages from at least 2). maybe submitting old browser tabs with obsolete form data? |
Yes, cleaning up ahmedsayeed1982 spam. I did my best to revert the nosy list, component, versions, and assigned to changes. What did I mess up? |
See bpo-12168 for a similar cleanup by Eryk Sun. There was approx. 20 spammed issues. Eryk fixed most of them; I did a couple. |
See the changelog entry for 2021-11-04 10:31:24 (and the other ticket where Guido just commented) (and thanks for cleaning spam!) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: