Open artyom opened 6 years ago
note: This seems to be related to this line, and its behavior looks reasonable.
I have investigated the issue and confirmed that this comment is incorrect, or at least the current (*URL) String()
implementation is wrong.
In fact, query components aren't escaped at all, not only in this example.
If the comment is positive, I think we should escape the query component appropriately.
/cc @tombergan
@namusyaka I think you are mistaken. The problem is with all forms of Parse which does no validation on the query or fragment pieces. The parse of the uri should have failed. Since it does not, the Fragment or RawQuery fields are incorrect and hence String() which is doing the right thing appears to provide a bad url.
All that has to happen is to apply validation of the query and fragment pieces in parse, and that should solve the issues. It might start breaking code that is sending around "bad" URLs.
Its not clear that this can be fixed given the behavior of shouldEscape() which states that most of the sub-delims should escape.
@fraenkel Yes, I knew it's more easy to understand the behavior.
However, if your opinion will reflect to the implementation, another cases such as http://example.com/foo bar
, http://example.com/foo? bar
and http://example.com/foo?bar# baz
should be failed on parse, and then I'm worried that breaks backword-compatibility.
Change https://golang.org/cl/99135 mentions this issue: net/url: reject invalid query strings when parsing URLs.
Copying my comment from the CL:
I changed the commit message to accurately reflect what later versions of this CL did. It now says:
net/url: escape URL.RawQuery on Parse if it contains invalid characters
But while reviewing this, I'm worried it might change the behavior of:
https://golang.org/pkg/net/url/#URL.Query which says:
"It silently discards malformed value pairs. To check errors use ParseQuery."
Before it silently discarded things, and with this CL it would start returning escaped versions instead. Do we care?
I think we probably should wait for Go 1.12 at this point. This needs a decision on what to do.
Reopening, as the fix is being reverted.
Change https://golang.org/cl/137716 mentions this issue: Revert "net/url: escape URL.RawQuery on Parse if it contains invalid characters"
@bradfitz - Any thoughts on this ? Or do we want to push to 1.13 ?
I'm kinda done with net/url.URL changes. They're always problematic compatibility-wise.
Definitely not for Go 1.12.
Change https://golang.org/cl/159157 mentions this issue: net/url, net/http: reject control characters in URLs
@gopherbot please open backport issues.
This has security implications, and CL 159157 is safe enough to backport.
Backport issue(s) opened: #29922 (for 1.10), #29923 (for 1.11).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.
Change https://golang.org/cl/159478 mentions this issue: [release-branch.go1.10] net/url, net/http: reject control characters in URLs
Change https://golang.org/cl/160178 mentions this issue: net/url, net/http: relax CTL-in-URL validation to only ASCII CTLs
Change https://golang.org/cl/160678 mentions this issue: [release-branch.go1.10] net/http, net/url: reject control characters in URLs
Change https://golang.org/cl/160798 mentions this issue: [release-branch.go1.11] net/http, net/url: reject control characters in URLs
Is there anything else to do for this issue?
Change https://golang.org/cl/162960 mentions this issue: doc/go1.12: document net/url.Parse now rejecting ASCII CTLs
Change https://golang.org/cl/162826 mentions this issue: [release-branch.go1.12] doc/go1.12: document net/url.Parse now rejecting ASCII CTLs
What did you do?
https://play.golang.org/p/hdX1zpv3BN
What did you expect to see?
I expect either url.Parse return a non-nil error or URL.String method return fully escaped url representation —
http://example.com/bad%20path/?bad%20query#bad%20fragment
— with query being escaped the same way as path or fragment.What did you see instead?
For the reference, such url is rejected by net/http.Server: https://play.golang.org/p/2gujmbXZlu
Does this issue reproduce with the latest release (go1.9.2)?
Yes
System details
https://tools.ietf.org/html/rfc3986#section-3.4 states that query component should be defined as (appendix A):
There's no whitespace character in this list. whatwg agrees on that: