Skip to content

fix(network): read tabs, line breaks, an IPv6 zone and one-sided credentials in a proxy value as 0.8 did - #91

Merged
AltaMills merged 4 commits into
refactorfrom
ark/go-proxy-strip-tabs
Dec 3, 2026
Merged

AltaMills merged 4 commits into
refactorfrom
ark/go-proxy-strip-tabs

Conversation

@AltaMills

@AltaMills AltaMills commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #90 (the review thread on internal/proxy/proxy.go there). 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
 	}
value                                  0.8                      before (cc813c0)              now
http://user:demo\nword@proxy:3128      password "demoword"      password "demo\nword"         password "demoword"
http://us\ter:pw@proxy:3128            user "user"              user "us\ter"                 user "user"
http://pro\txy:3128, ht\ntp://…,        proxy:3128               "not a valid proxy URL"       proxy:3128
  http://proxy:31\n28
http://user:pa%0Ass@proxy:3128         password "pa\nss"        password "pa\nss"             password "pa\nss"
http://[fe80::1%25en0]:3128,           refused                  proxy [fe80::1%en0]:3128      refused
  http://100%25.example:3128
http://[::\t1%25lo0]:3128              refused                  refused                       refused
http://user@proxy:3128,                no Proxy-Authorization   "user:", ":fixture"           no Proxy-Authorization
  http://:fixture@proxy:3128

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) and 8db8c29 (this branch), run with --format json against 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:

    case                                         before (cc813c0)                       after (8db8c29)
    balance get, HTTPS_PROXY password            CONNECT with "user:demo\nword"         CONNECT with "user:demoword"
      "demo\nword" (literal newline)
    balance get, HTTPS_PROXY host "127.0.\t0.1"  "HTTPS_PROXY is not a valid proxy      CONNECT through 127.0.0.1
                                                 URL (...)", proxy saw nothing
    balance get, HTTPS_PROXY=http://fake:        CONNECT to the proxy on ::1 with       "HTTPS_PROXY is not a valid proxy URL
      fixture@[::1%25lo0]:<port>                 "fake:fixture"                         (...)", proxy saw nothing
    balance get, HTTPS_PROXY=http://user@…,      CONNECT with "user:", ":fixture",       CONNECT without Proxy-Authorization
      :fixture@…, user:@…, us\ner:\n@…           "user:", "us\ner:\n"
    balance get, HTTPS_PROXY=http://user:        CONNECT with "user:fixture"            CONNECT with "user:fixture"
      fixture@…
    
  • The same five proxy URLs through undici 7.30.2's ProxyAgent against the same kind of mock: Proxy-Authorization only for user:fixture, as now.

  • 0.8's check (new URL plus undici 7.30.2's ProxyAgent, as isUsableProxyUrl does) against Go's FromEnv on 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.

  • TestValidProxyValues gains 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, and 100%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 %0A too, taking a host with a %, keeping one-sided credentials, and dropping them only when both are missing.

  • Locally, darwin/arm64, go test ./... at 8db8c29: 981 passed, 0 failed, 18 skipped (the 0.8.8 interoperability and OS key store tests, which need MESHY_TEST_TS_CLI and MESHY_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.

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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.
@AltaMills AltaMills changed the title fix(network): drop tabs and line breaks from a proxy value, as 0.8 did fix(network): drop tabs and line breaks from a proxy value and refuse an IPv6 zone, as 0.8 did Dec 3, 2026
…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.
@AltaMills AltaMills changed the title fix(network): drop tabs and line breaks from a proxy value and refuse an IPv6 zone, as 0.8 did fix(network): read tabs, line breaks, an IPv6 zone and one-sided credentials in a proxy value as 0.8 did Dec 3, 2026
@AltaMills
AltaMills merged commit e22e67d into refactor Dec 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant