Repository navigation
fix(network): read tabs, line breaks, an IPv6 zone and one-sided credentials in a proxy value as 0.8 did - #91
Merged
Merged
Conversation
0.8 read a proxy value as a WHATWG URL, which drops literal tabs, carriage returns and line feeds wherever they are. The Go CLI kept them: in a user or password it escaped them, so the proxy got a different password, and in the scheme, host or port it refused the value. Now they are dropped before parsing; an escaped one such as %0A stays, as in 0.8.
A WHATWG URL refuses a % left in a host once it is decoded, so 0.8 refused an IPv6 zone (http://[fe80::1%25en0]:3128) and 100%25.example. Go takes both. Dropping tabs and line breaks also made such a value reachable from one that held a tab, which Go had refused. A host with a % now stops every request with the error that names the variable, as in 0.8.
…word undici sent Proxy-Authorization only when the proxy URL held both a user and a password; with one of them empty it used the proxy without credentials. Go sends whatever userinfo the URL has, so http://user@proxy:3128 sent "user:" and http://:pw@proxy:3128 sent the password alone. Dropping tabs and line breaks also made such a value reachable from one Go had refused. The parsed proxy URL now keeps credentials only when both are given. The credentials test's comment says what the table checks: characters as typed, escapes decoded, literal tabs and line breaks dropped.
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.
Summary
Follow-up to #90 (the review thread on
internal/proxy/proxy.gothere). 0.8 read a proxy value as a WHATWG URL, which drops literal tabs, carriage returns and line feeds wherever they are; the Go CLI kept them. A WHATWG URL also refuses a%left in a host once it is decoded, so 0.8 refused an IPv6 zone; the Go CLI took one, and dropping a tab made one reachable from a value Go had refused. And undici sent proxy credentials only when both a user and a password were given; Go sent whatever userinfo the URL had (user:,:password).func parse(value string) (*url.URL, bool) { + // A WHATWG URL drops tabs and line breaks wherever they are; an escaped + // one, such as %0A, stays. + value = strings.NewReplacer("\t", "", "\r", "", "\n", "").Replace(value) u, err := url.Parse(escape(value)) - if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Opaque != "" || u.Hostname() == "" { + if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Opaque != "" || u.Hostname() == "" || + strings.Contains(u.Hostname(), "%") { return nil, false … if password, _ := u.User.Password(); !utf8.ValidString(u.User.Username()) || !utf8.ValidString(password) { return nil, false + } else if u.User.Username() == "" || password == "" { + u.User = nil // undici sent credentials only with both a user and a password }D-099's accepted-values bullet says so. Still refused where 0.8 took it: a host name written percent-encoded (
pro%78y.example), which Go refuses unless the escape is outside ASCII; the error names the variable, nothing goes direct.Evidence
Before / After: the binaries built from
cc813c0(base) and8db8c29(this branch), run with--format jsonagainst a local mock proxy that refuses CONNECT (403 on 127.0.0.1; 407 on ::1 for the zone case) and records the Basic credentials, with a fake key and a temporary config directory:The same five proxy URLs through undici 7.30.2's
ProxyAgentagainst the same kind of mock: Proxy-Authorization only foruser:fixture, as now.0.8's check (
new URLplus undici 7.30.2'sProxyAgent, asisUsableProxyUrldoes) against Go'sFromEnvon 11 values with literal or escaped tabs and line breaks in the scheme, user, password, host, port and path: 7 differed before, none now. On 9 values with a zone or a%in the host: 5 differed before, 1 now (pro%78y.example, above). The 60 values compared for fix(network): requests honor HTTPS_PROXY, HTTP_PROXY and NO_PROXY as 0.8 does #90 give the same results as before.TestValidProxyValuesgains a value with tabs and line breaks in the scheme, host and port, and credentials with literal ones (dropped) and escaped ones (kept). The invalid-value table gains a zoned IPv6 host with credentials, one reached by dropping a tab, and100%25.example; the credentials table gains five values with a user or a password missing, which keep no credentials. Mutation probes, each turned a test red: not dropping them, dropping an escaped%0Atoo, taking a host with a%, keeping one-sided credentials, and dropping them only when both are missing.Locally, darwin/arm64,
go test ./...at8db8c29: 981 passed, 0 failed, 18 skipped (the 0.8.8 interoperability and OS key store tests, which needMESHY_TEST_TS_CLIandMESHY_TEST_OS_KEYRING).Merge Danger
Door: two-way. Revert restores keeping them.
Blast Radius: proxy values holding a literal tab, carriage return or line feed, a host with a
%(an IPv6 zone), or a user without a password (or the reverse); no other value changes.