From dd98398e77dd0e4340116fe125b26fe4b314c69b Mon Sep 17 00:00:00 2001 From: Zeusina Date: Sat, 10 Oct 2026 17:44:13 +0300 Subject: [PATCH] fix(recovery): validate diagnostic DNS addresses Co-authored-by: GPT-6 --- cmd/zapret-autotune/recover.go | 8 +++++++- cmd/zapret-autotune/recovery_primitives_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/zapret-autotune/recover.go b/cmd/zapret-autotune/recover.go index 74db719..10cf81f 100644 --- a/cmd/zapret-autotune/recover.go +++ b/cmd/zapret-autotune/recover.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "io" + "net" "os" "regexp" "strconv" @@ -95,7 +96,7 @@ var earlySuccessResult = regexp.MustCompile(`^ OK median [0-9]+ms, [0-9]+\.[0 var earlyCheckPreamble = regexp.MustCompile("^(! --workers has no effect on `check` \\(it verifies strategies sequentially by design\\)\n)?" + `=== Checking prerequisites ===\n OK nfqws2: /[^\s]+\n OK nft\n OK nft queue support\n` + `check loaded 2 strategies from /[^\s]+, --take [0-9]+, --passes 3\n( ISP: AS[0-9]+ [^\n]+\n)?` + - `=== DNS resolve ===\n dns mode: auto\n ([a-z0-9.-]+) -> [0-9a-fA-F:.]+(?:, [0-9a-fA-F:.]+)* \(via (?:system|doh \(auto-fallback\))\)$`) + `=== DNS resolve ===\n dns mode: auto\n ([a-z0-9.-]+) -> ([0-9a-fA-F:.]+(?:, [0-9a-fA-F:.]+)*) \(via (?:system|doh \(auto-fallback\))\)$`) var earlyCheckSummary = regexp.MustCompile(`^ total: 2 \| working: ([01]) \| elapsed: [0-9]+\.[0-9]s\n OK JSON report → (?:/[^\s]+|[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}_check\.json)$`) // This is rejection evidence only, never qualification evidence. Unknown CLI @@ -154,6 +155,11 @@ func candidateEarlyTimeout(raw, diagnostics []byte, args, group, host string) bo if preamble == nil || preamble[3] != host { return false } + for _, ip := range strings.Split(preamble[4], ", ") { + if net.ParseIP(ip) == nil { + return false + } + } parts = strings.Split(parts[1], "\n=== Check summary ===\n") if len(parts) != 2 { return false diff --git a/cmd/zapret-autotune/recovery_primitives_test.go b/cmd/zapret-autotune/recovery_primitives_test.go index b19d1c5..a19adc6 100644 --- a/cmd/zapret-autotune/recovery_primitives_test.go +++ b/cmd/zapret-autotune/recovery_primitives_test.go @@ -272,6 +272,13 @@ func TestCandidateEarlyTimeoutRemoteCaptures(t *testing.T) { } for _, pair := range [][2]string{ {c.ips, "142.251.156.4, garbage"}, + {c.ips, "dead"}, + {c.ips, "999.999.999.999"}, + {c.ips, "142.251.156.4, dead"}, + {c.ips, "999.999.999.999, 142.251.156.4"}, + {c.ips, "2001:db8:::1"}, + {c.ips, "142.251.156.4,2001:db8::1"}, + {c.ips, "142.251.156.4, 2001:db8::1"}, {"via doh (auto-fallback)", "via unknown"}, {c.path, "unknown-output"}, {c.path, c.path + "\nnfqws2 exited with status 1"}, @@ -283,6 +290,11 @@ func TestCandidateEarlyTimeoutRemoteCaptures(t *testing.T) { if !candidateEarlyTimeout(report, []byte(strings.Replace(diagnostic, "via doh (auto-fallback)", "via system", 1)), c.args, "frontend", "www.youtube.com") { t.Fatal("system-resolved addresses rejected") } + for _, ips := range []string{"2001:db8::1", "142.251.156.4, 2001:db8::1", "::ffff:192.0.2.1"} { + if !candidateEarlyTimeout(report, []byte(strings.Replace(diagnostic, c.ips, ips, 1)), c.args, "frontend", "www.youtube.com") { + t.Fatalf("valid IP literals rejected: %q", ips) + } + } }) } }