Repository navigation
Conversation
Percent-encoding the whole Location header (from 63b2b5c) also encoded non-ASCII characters in the host, and a percent-encoded host is not a valid IDNA name, so redirects to internationalized domain names failed at resolution. Encode only the path, query and fragment, and IDNA-encode (punycode) a non-ASCII host, matching WHATWG/browser handling. Fixes tornadoweb#3870
Member
|
Closing in favor of #3873. This PR decodes the location header as latin1, which is inconsistent with what web browsers use (utf8). |
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.
Fixes #3870.
63b2b5c percent-encodes the entire
Locationvalue, which also rewrites non-ASCII characters in the host. A percent-encoded host is not a valid IDNA name (caf%E9.example), so the redirected request failed at resolution.Now only the path, query and fragment are percent-encoded; a non-ASCII host is IDNA-encoded (punycode,
café.example->xn--caf-dma.example), matching WHATWG/browser handling. Punycode also keeps theHostheader of the followed request ASCII, so strict servers (including tornado's own_ABNF.hostcheck) accept it.Regression test: a loopback server returns
302with a latin-1Location: http://café.example:PORT/...;socket.getaddrinfois patched to log the host handed to the resolver and map the punycode name to loopback. The test asserts the resolver seesxn--caf-dma.exampleand the redirect completes with 200. It fails on current master (resolver receivescaf%E9.example).Verified:
tornado.test.simple_httpclient_test+httpclient_test+web_testall pass; full suite passes except two pre-existing pycurl/Schannel environment errors (test_reuse_certs,test_digest_auth_non_ascii) that fail identically without this change.