fix: resolve managed probes through owned SS DNS

Canonicalize validated managed proxy schemes to socks5h for Player, metadata, resource and warmup probes; retain listener ownership, TLS/privacy checks and legacy CLI/pinned checker semantics. Stop canceled inventory requests before Player and metadata fallback, with explicit cancellation and runner-only DNS regressions.

Verification: full native Go tests, affected race tests, go vet and static/config/supervision fixtures passed. An extra whole-package race attempt exceeded its 180s deadline in unrelated TestTuneCLI; affected race coverage completed separately.

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-12 22:28:13 +03:00
1 parent e9a28c8cd3
commit 1afee7d3bd
20 files changed
+207 -25

No files matched your search

+9 -1
View File
@@ -257,13 +257,21 @@ signed URLs; use `docker compose ... config --quiet` for validation.
| `ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS` | JSON array of 1..5 unique VideoIDs; defaults to only the primary ID; explicitly forwarded | | `ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS` | JSON array of 1..5 unique VideoIDs; defaults to only the primary ID; explicitly forwarded |
| `ZAPRET_AUTOTUNE_HOST_SOCKS_PORT` | `11080`; choose an available TCP/UDP port 1–65535, published only on `127.0.0.1` | | `ZAPRET_AUTOTUNE_HOST_SOCKS_PORT` | `11080`; choose an available TCP/UDP port 1–65535, published only on `127.0.0.1` |
| `SOCKS_PORT` | Supplied deployment fixes internal listener to `1080`; not a host-port override | | `SOCKS_PORT` | Supplied deployment fixes internal listener to `1080`; not a host-port override |
| `ZAPRET_AUTOTUNE_SOCKS_PROXY` | Fixed `socks5://127.0.0.1:1080` inside this target, no credentials/direct fallback | | `ZAPRET_AUTOTUNE_SOCKS_PROXY` | Fixed `socks5h://127.0.0.1:1080` inside this target, no credentials/direct fallback |
| `ZAPRET_AUTOTUNE_VIDEO_ID` | `dQw4w9WgXcQ`; exactly 11 ASCII letters, digits, `_` or `-` | | `ZAPRET_AUTOTUNE_VIDEO_ID` | `dQw4w9WgXcQ`; exactly 11 ASCII letters, digits, `_` or `-` |
| `ZAPRET_AUTOTUNE_HEALTH_INTERVAL` | `5m`; duration in `(0,24h]` for monitor | | `ZAPRET_AUTOTUNE_HEALTH_INTERVAL` | `5m`; duration in `(0,24h]` for monitor |
| `ZAPRET_AUTOTUNE_FAILURE_THRESHOLD` | `3`; integer 1–1000 for monitor | | `ZAPRET_AUTOTUNE_FAILURE_THRESHOLD` | `3`; integer 1–1000 for monitor |
| `ZAPRET_AUTOTUNE_RECOVERY_COOLDOWN` | `30m`; duration in `(0,168h]` for monitor | | `ZAPRET_AUTOTUNE_RECOVERY_COOLDOWN` | `30m`; duration in `(0,168h]` for monitor |
| `ZAPRET_AUTOTUNE_DB` | Fixed `/var/lib/zapret-autotune/target/candidates.db` | | `ZAPRET_AUTOTUNE_DB` | Fixed `/var/lib/zapret-autotune/target/candidates.db` |
Managed Player, metadata, image, media and warmup requests send hostnames through
the owned SS listener (`socks5h`), so they respect target-native DNS instead of
bypassing it with curl's local resolution. Older private environment overrides
using `socks5` are canonicalized internally after validation; arbitrary proxies
remain rejected by the listener/port/process ownership guard. Legacy public CLI
discovery and root checker `--resolve` pinning are unchanged. This corrects a DNS
path bypass, not a proven explanation of earlier peer certificate failures.
The monitor's three policy flags override corresponding environment defaults; The monitor's three policy flags override corresponding environment defaults;
explicit empty/invalid environment settings are rejected. The entrypoint accepts explicit empty/invalid environment settings are rejected. The entrypoint accepts
no arguments. Compose forwards the primary/sample VideoIDs and service/mode settings. no arguments. Compose forwards the primary/sample VideoIDs and service/mode settings.
+32
View File
@@ -114,3 +114,35 @@ func validLoopbackSOCKS(raw string) bool {
host := u.Hostname() host := u.Hostname()
return strings.EqualFold(host, "localhost") || net.ParseIP(host).IsLoopback() return strings.EqualFold(host, "localhost") || net.ParseIP(host).IsLoopback()
} }
// Managed probes send hostnames through the owned SS listener, not local DNS.
// Legacy public discovery/health parsing deliberately keeps socks5 semantics.
func managedProbeProxy(raw string) (string, error) {
u, err := url.Parse(raw)
if err != nil || (u.Scheme != "socks5" && u.Scheme != "socks5h") || strings.IndexFunc(raw, func(r rune) bool { return r < 32 || r == 127 }) >= 0 {
return "", fmt.Errorf("invalid managed SOCKS proxy")
}
if !validLoopbackSOCKS(strings.Replace(raw, "socks5h://", "socks5://", 1)) {
return "", fmt.Errorf("invalid managed SOCKS proxy")
}
u.Scheme = "socks5h"
return u.String(), nil
}
func parseManagedHealthConfig(lookup func(string) (string, bool)) (healthConfig, error) {
// Reuse all legacy setting validation without changing its public contract.
cfg, err := parseHealthConfig(func(key string) (string, bool) {
raw, ok := lookup(key)
if key == "ZAPRET_AUTOTUNE_SOCKS_PROXY" && ok {
if proxy, e := managedProbeProxy(raw); e == nil {
return strings.Replace(proxy, "socks5h://", "socks5://", 1), true
}
}
return raw, ok
})
if err != nil {
return cfg, err
}
cfg.SOCKSProxy, err = managedProbeProxy(cfg.SOCKSProxy)
return cfg, err
}
+1 -1
View File
@@ -37,7 +37,7 @@ func run(args []string, stdout, stderr io.Writer) int {
func runWithPlayer(args []string, stdout, stderr io.Writer, player playerRunner) int { func runWithPlayer(args []string, stdout, stderr io.Writer, player playerRunner) int {
if len(args) == 1 && args[0] == "target-config-check" { if len(args) == 1 && args[0] == "target-config-check" {
if _, err := parseHealthConfig(os.LookupEnv); err != nil { if _, err := parseManagedHealthConfig(os.LookupEnv); err != nil {
fmt.Fprintln(stderr, "configerror: invalid target health/service configuration") fmt.Fprintln(stderr, "configerror: invalid target health/service configuration")
return 64 return 64
} }
@@ -41,8 +41,12 @@ func newManagedAssetVerifier(target managedDeps) func(context.Context, storedCan
func newManagedAssetRuntime(target managedDeps) managedAssetRuntime { func newManagedAssetRuntime(target managedDeps) managedAssetRuntime {
proxy, _ := target.lookup("ZAPRET_AUTOTUNE_SOCKS_PROXY") proxy, _ := target.lookup("ZAPRET_AUTOTUNE_SOCKS_PROXY")
proxy, proxyErr := managedProbeProxy(proxy)
r := managedAssetRuntime{proxy: proxy, curl: runResourceCurl} r := managedAssetRuntime{proxy: proxy, curl: runResourceCurl}
r.guard = func() error { r.guard = func() error {
if proxyErr != nil {
return proxyErr
}
if _, err := managedRuntimeGuard(target); err != nil { if _, err := managedRuntimeGuard(target); err != nil {
return err return err
} }
+15 -1
View File
@@ -71,10 +71,21 @@ type managedServiceInventory struct {
func managedServiceResources(cfg healthConfig, player func(context.Context) ([]byte, error), page playerRunner) func(context.Context) (managedServiceInventory, error) { func managedServiceResources(cfg healthConfig, player func(context.Context) ([]byte, error), page playerRunner) func(context.Context) (managedServiceInventory, error) {
return func(ctx context.Context) (managedServiceInventory, error) { return func(ctx context.Context) (managedServiceInventory, error) {
i := managedServiceInventory{images: make(map[string]string), proxy: cfg.SOCKSProxy, runner: runResourceCurl} i := managedServiceInventory{images: make(map[string]string), proxy: cfg.SOCKSProxy, runner: runResourceCurl}
if err := ctx.Err(); err != nil {
return i, managedRecoveryContextError(ctx, err)
}
proxy, err := managedProbeProxy(cfg.SOCKSProxy)
if err != nil {
return i, &managedRecoveryFatal{Err: err}
}
i.proxy = proxy
body, err := player(ctx) body, err := player(ctx)
if err != nil { if err != nil {
return i, &managedResourceFailure{"front", managedFrontendHost, err} return i, &managedResourceFailure{"front", managedFrontendHost, err}
} }
if err := ctx.Err(); err != nil {
return i, managedRecoveryContextError(ctx, err)
}
var p struct { var p struct {
VideoDetails struct { VideoDetails struct {
Thumbnail struct { Thumbnail struct {
@@ -97,6 +108,9 @@ func managedServiceResources(cfg healthConfig, player func(context.Context) ([]b
i.resourceErr = &managedResourceFailure{"media", "unknown", err} i.resourceErr = &managedResourceFailure{"media", "unknown", err}
} }
for attempt := 0; attempt < 2; attempt++ { for attempt := 0; attempt < 2; attempt++ {
if err := ctx.Err(); err != nil {
return i, managedRecoveryContextError(ctx, err)
}
origin := "https://www.youtube.com/" origin := "https://www.youtube.com/"
if attempt == 1 { if attempt == 1 {
if !videoIDPattern.MatchString(cfg.VideoID) { if !videoIDPattern.MatchString(cfg.VideoID) {
@@ -108,7 +122,7 @@ func managedServiceResources(cfg healthConfig, player func(context.Context) ([]b
var output bytes.Buffer var output bytes.Buffer
out := &playerBoundedWriter{dst: &output, limit: 5 << 20} out := &playerBoundedWriter{dst: &output, limit: 5 << 20}
// Fixed trusted WWW origin; no redirects, credentials or diagnostics. // Fixed trusted WWW origin; no redirects, credentials or diagnostics.
err = page(bounded, []string{"--disable", "--silent", "--show-error", "--fail", "--noproxy", "", "--proxy", cfg.SOCKSProxy, "--proto", "=https", "--max-time", "30", "--max-filesize", "5242880", origin}, out, io.Discard) err = page(bounded, []string{"--disable", "--silent", "--show-error", "--fail", "--noproxy", "", "--proxy", proxy, "--proto", "=https", "--max-time", "30", "--max-filesize", "5242880", origin}, out, io.Discard)
requestErr := bounded.Err() requestErr := bounded.Err()
cancel() cancel()
if ctx.Err() != nil { if ctx.Err() != nil {
@@ -72,9 +72,10 @@ func TestManagedAvatarInventoryFallback(t *testing.T) {
t.Fatal("unbounded metadata or diagnostics") t.Fatal("unbounded metadata or diagnostics")
} }
joined := strings.Join(args, " ") joined := strings.Join(args, " ")
if strings.Contains(joined, "private=") || strings.Contains(joined, "--insecure") || strings.Contains(joined, "--location") || !strings.Contains(joined, "--proto =https") || !strings.Contains(joined, "--max-filesize 5242880") || !strings.Contains(joined, "--proxy "+cfg.SOCKSProxy) { if strings.Contains(joined, "private=") || strings.Contains(joined, "--insecure") || strings.Contains(joined, "--location") || !strings.Contains(joined, "--proto =https") || !strings.Contains(joined, "--max-filesize 5242880") || !strings.Contains(joined, "--proxy socks5h://127.0.0.1:11080") {
t.Fatal("unsafe metadata request") t.Fatal("unsafe metadata request")
} }
assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:11080")
body, origin := tc.home, "https://www.youtube.com/" body, origin := tc.home, "https://www.youtube.com/"
if calls == 2 { if calls == 2 {
body, origin = tc.watch, "https://www.youtube.com/watch?v="+cfg.VideoID body, origin = tc.watch, "https://www.youtube.com/watch?v="+cfg.VideoID
@@ -133,17 +134,40 @@ func TestManagedAvatarMetadataHealthClassification(t *testing.T) {
} }
func TestManagedAvatarInventoryCancellationNoFallback(t *testing.T) { func TestManagedAvatarInventoryCancellationNoFallback(t *testing.T) {
for _, timing := range []string{"before-player", "after-player", "during-home"} {
t.Run(timing, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if timing == "before-player" {
cancel() cancel()
calls := 0 }
resources := managedServiceResources(healthConfig{VideoID: "dQw4w9WgXcQ"}, func(context.Context) ([]byte, error) { players, pages := 0, 0
resources := managedServiceResources(healthConfig{VideoID: "dQw4w9WgXcQ", SOCKSProxy: "socks5h://127.0.0.1:11080"}, func(context.Context) ([]byte, error) {
players++
if timing == "after-player" {
cancel()
}
return []byte(`{"playabilityStatus":{"status":"OK"}}`), nil return []byte(`{"playabilityStatus":{"status":"OK"}}`), nil
}, func(ctx context.Context, _ []string, _, _ io.Writer) error { }, func(ctx context.Context, args []string, out, _ io.Writer) error {
calls++ pages++
return ctx.Err() assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:11080")
if args[len(args)-1] != "https://www.youtube.com/" {
t.Fatal("watch fallback after cancellation", args)
}
cancel()
_, err := io.WriteString(out, `var ytInitialData = {};`)
return err
}) })
i, err := resources(ctx) i, err := resources(ctx)
if calls != 1 || !errors.Is(err, context.Canceled) || i.images["yt3.ggpht.com"] != "" { wantPlayers, wantPages := 1, 0
t.Fatal("cancellation lost or fallback attempted", calls, err) if timing == "before-player" {
wantPlayers = 0
} else if timing == "during-home" {
wantPages = 1
}
if players != wantPlayers || pages != wantPages || !errors.Is(err, context.Canceled) || i.images["yt3.ggpht.com"] != "" {
t.Fatal("cancellation lost or request after cancellation", players, pages, err)
}
})
} }
} }
+3 -2
View File
@@ -395,7 +395,8 @@ func managedRuntimeGuard(d managedDeps) (int, error) {
portText, _ := d.lookup("SOCKS_PORT") portText, _ := d.lookup("SOCKS_PORT")
port, portErr := strconv.Atoi(portText) port, portErr := strconv.Atoi(portText)
proxy, _ := d.lookup("ZAPRET_AUTOTUNE_SOCKS_PROXY") proxy, _ := d.lookup("ZAPRET_AUTOTUNE_SOCKS_PROXY")
if portErr != nil || port < 1 || port > 65535 || strconv.Itoa(port) != portText || proxy != "socks5://127.0.0.1:"+portText { proxy, proxyErr := managedProbeProxy(proxy)
if portErr != nil || port < 1 || port > 65535 || strconv.Itoa(port) != portText || proxyErr != nil || proxy != "socks5h://127.0.0.1:"+portText {
return 2, fmt.Errorf("managed SOCKS proxy must match the target SOCKS_PORT listener") return 2, fmt.Errorf("managed SOCKS proxy must match the target SOCKS_PORT listener")
} }
if d.verifyRuntime == nil || d.verifySOCKS == nil { if d.verifyRuntime == nil || d.verifySOCKS == nil {
@@ -535,7 +536,7 @@ func managedActivate(m *managedTransaction, d managedDeps, ids []int64, expected
if err != nil || !info.Mode().IsRegular() || info.Mode().Perm()&0111 == 0 { if err != nil || !info.Mode().IsRegular() || info.Mode().Perm()&0111 == 0 {
return fmt.Errorf("target zapret daemon init executable unavailable") return fmt.Errorf("target zapret daemon init executable unavailable")
} }
cfg, err := parseHealthConfig(d.lookup) cfg, err := parseManagedHealthConfig(d.lookup)
if err != nil { if err != nil {
return err return err
} }
+1 -1
View File
@@ -47,7 +47,7 @@ func managedCLIFixture(t *testing.T) (managedDeps, map[string]string, *int) {
return nil return nil
}, },
player: func(_ context.Context, args []string, stdout, _ io.Writer) error { player: func(_ context.Context, args []string, stdout, _ io.Writer) error {
if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5://127.0.0.1:11080|") { if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5h://127.0.0.1:11080|") {
t.Fatalf("unsafe health argv: %q", args) t.Fatalf("unsafe health argv: %q", args)
} }
_, err := io.WriteString(stdout, `{"playabilityStatus":{"status":"OK"}}`) _, err := io.WriteString(stdout, `{"playabilityStatus":{"status":"OK"}}`)
+87
View File
@@ -0,0 +1,87 @@
package main
import (
"context"
"io"
"strings"
"testing"
)
func assertManagedDNSArgs(t *testing.T, args []string, proxy string) {
t.Helper()
joined := strings.Join(args, "|")
if !strings.Contains(joined, "--noproxy||--proxy|"+proxy+"|") {
t.Fatalf("missing managed remote DNS proxy: %q", args)
}
for _, arg := range args {
if arg == "-k" || arg == "--insecure" || strings.HasPrefix(arg, "--resolve") || strings.HasPrefix(arg, "--connect-to") {
t.Fatalf("DNS pin or TLS bypass: %q", args)
}
}
}
func TestManagedProbeProxy(t *testing.T) {
for _, raw := range []string{"socks5://127.0.0.1:1080", "socks5h://127.0.0.1:1080", "socks5://localhost:1080", "socks5h://[::1]:1080"} {
got, err := managedProbeProxy(raw)
if err != nil || got != strings.Replace(raw, "socks5://", "socks5h://", 1) {
t.Fatal(raw, got, err)
}
}
for _, raw := range []string{"", "http://127.0.0.1:1080", "socks5h://proxy.example:1080", "socks5h://user:secret@127.0.0.1:1080", "socks5h://127.0.0.1:0", "socks5h://127.0.0.1:65536", "socks5h://127.0.0.1:1080/", "socks5h://127.0.0.1:1080?", "socks5h://127.0.0.1:1080#", "socks5h://127.0.0.1:1080\n", "socks5h://127.0.0.1:1080\x7f"} {
if got, err := managedProbeProxy(raw); err == nil || got != "" || strings.Contains(err.Error(), "secret") {
t.Fatal("unsafe proxy accepted or leaked", got, err)
}
}
}
func TestManagedDNSProductionPlayerAndGuard(t *testing.T) {
for _, scheme := range []string{"socks5", "socks5h"} {
t.Run(scheme, func(t *testing.T) {
target, env, _ := managedCLIFixture(t)
env["ZAPRET_AUTOTUNE_SOCKS_PROXY"] = scheme + "://127.0.0.1:11080"
owned := 0
target.verifySOCKS = func(port int) error {
if port != 11080 {
t.Fatal(port)
}
owned++
return nil
}
requests := 0
target.player = func(_ context.Context, args []string, out, _ io.Writer) error {
assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:11080")
if args[len(args)-1] != playerURL {
t.Fatal("Player hostname changed", args)
}
requests++
_, err := io.WriteString(out, `{"playabilityStatus":{"status":"OK"},"streamingData":{"serverAbrStreamingUrl":"https://fresh.googlevideo.com/video?private=secret"}}`)
return err
}
r, _, _ := recoveryFixture(t, false)
d, err := managedRecoveryDependencies(target, r.db, r.scan, r.check, r.run)
if err != nil {
t.Fatal(err)
}
if status, err := d.health(context.Background()); err != nil || status != "OK" {
t.Fatal(status, err)
}
if host, err := d.discover(context.Background()); err != nil || host != "fresh.googlevideo.com" {
t.Fatal(host, err)
}
if requests != 2 || owned != 3 {
t.Fatal(requests, owned)
}
for _, proxy := range []string{scheme + "://127.0.0.1:1080", scheme + "://localhost:11080", scheme + "://[::1]:11080", scheme + "://proxy.example:11080"} {
env["ZAPRET_AUTOTUNE_SOCKS_PROXY"] = proxy
if _, err := managedRuntimeGuard(target); err == nil {
t.Fatal("unowned endpoint accepted", proxy)
}
}
})
}
lookup := configLookup(map[string]string{"ZAPRET_AUTOTUNE_SOCKS_PROXY": "socks5://127.0.0.1:11080"})
legacy, err := parseHealthConfig(lookup)
if err != nil || legacy.SOCKSProxy != "socks5://127.0.0.1:11080" || validDiscoveryProxy("socks5h://127.0.0.1:11080") {
t.Fatal("legacy proxy contract changed", legacy, err)
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ func managedExperimentalSuffix(m *managedTransaction, d managedDeps) error {
if err != nil || fmt.Sprintf("%x", sha256.Sum256(lua)) != managedGooglevideoLuaHash { if err != nil || fmt.Sprintf("%x", sha256.Sum256(lua)) != managedGooglevideoLuaHash {
return fmt.Errorf("native Lua identity mismatch") return fmt.Errorf("native Lua identity mismatch")
} }
cfg, err := parseHealthConfig(d.lookup) cfg, err := parseManagedHealthConfig(d.lookup)
if err != nil { if err != nil {
return err return err
} }
@@ -56,6 +56,7 @@ func TestManagedGooglevideoOwnedPostWarmupProducer(t *testing.T) {
r, c, resources, events := googlevideoRuntimeFixture(t) r, c, resources, events := googlevideoRuntimeFixture(t)
runner, calls := r.curl, 0 runner, calls := r.curl, 0
r.curl = func(ctx context.Context, args []string, stdin io.Reader, out, diagnostic io.Writer) error { r.curl = func(ctx context.Context, args []string, stdin io.Reader, out, diagnostic io.Writer) error {
assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:1080")
calls++ calls++
if calls <= 2 { if calls <= 2 {
return context.DeadlineExceeded return context.DeadlineExceeded
+1 -1
View File
@@ -16,7 +16,7 @@ import (
// Provisioning owns executable, database, proxy and target paths; no path flags. // Provisioning owns executable, database, proxy and target paths; no path flags.
func managedMonitorConfig(args []string, lookup func(string) (string, bool)) (healthConfig, error) { func managedMonitorConfig(args []string, lookup func(string) (string, bool)) (healthConfig, error) {
cfg, err := parseHealthConfig(lookup) cfg, err := parseManagedHealthConfig(lookup)
if err != nil { if err != nil {
return cfg, err return cfg, err
} }
@@ -352,7 +352,7 @@ func TestManagedMonitorProductionAdapterBinding(t *testing.T) {
if ctx.Err() != nil { if ctx.Err() != nil {
t.Fatal(ctx.Err()) t.Fatal(ctx.Err())
} }
if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5://127.0.0.1:11080|") { if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5h://127.0.0.1:11080|") {
t.Fatal(args) t.Fatal(args)
} }
_, err := io.WriteString(out, `{"playabilityStatus":{"status":"OK"},"streamingData":{"serverAbrStreamingUrl":"https://fresh.googlevideo.com/video?secret=never-print"}}`) _, err := io.WriteString(out, `{"playabilityStatus":{"status":"OK"},"streamingData":{"serverAbrStreamingUrl":"https://fresh.googlevideo.com/video?secret=never-print"}}`)
@@ -578,7 +578,7 @@ func TestManagedMonitorCLIBindingAndCancellation(t *testing.T) {
requests := 0 requests := 0
d.player = func(ctx context.Context, args []string, out, _ io.Writer) error { d.player = func(ctx context.Context, args []string, out, _ io.Writer) error {
requests++ requests++
if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5://127.0.0.1:11080|") { if !strings.Contains(strings.Join(args, "|"), "--noproxy||--proxy|socks5h://127.0.0.1:11080|") {
t.Fatal(args) t.Fatal(args)
} }
if requests == 1 { if requests == 1 {
+1 -1
View File
@@ -52,7 +52,7 @@ func managedRecoveryDependencies(target managedDeps, db *sql.DB, scan cacheScan,
if _, err := managedRuntimeGuard(target); err != nil { if _, err := managedRuntimeGuard(target); err != nil {
return d, err return d, err
} }
cfg, err := parseHealthConfig(target.lookup) cfg, err := parseManagedHealthConfig(target.lookup)
if err != nil { if err != nil {
return d, err return d, err
} }
+2 -1
View File
@@ -223,7 +223,8 @@ func collectResourceTransfer(ctx context.Context, proxy, raw, host, protocol str
fail := func(err error) (assetTransfer, http.Header, error) { fail := func(err error) (assetTransfer, http.Header, error) {
return assetTransfer{}, nil, resourceFailure(ctx, err) return assetTransfer{}, nil, resourceFailure(ctx, err)
} }
if !validDiscoveryProxy(proxy) || runner == nil { proxy, proxyErr := managedProbeProxy(proxy)
if proxyErr != nil || runner == nil {
return fail(errors.New("invalid owned proxy or runner")) return fail(errors.New("invalid owned proxy or runner"))
} }
if _, err := privateResourceURL(raw, host); err != nil { if _, err := privateResourceURL(raw, host); err != nil {
@@ -63,6 +63,7 @@ func TestResourceChild(t *testing.T) {
if os.Getenv("AUTOTUNE_RESOURCE_CHILD") != "1" { if os.Getenv("AUTOTUNE_RESOURCE_CHILD") != "1" {
return return
} }
assertManagedDNSArgs(t, os.Args[3:], "socks5h://127.0.0.1:1080")
b, err := io.ReadAll(io.LimitReader(os.Stdin, 32<<10)) b, err := io.ReadAll(io.LimitReader(os.Stdin, 32<<10))
if err != nil { if err != nil {
os.Exit(3) os.Exit(3)
@@ -84,9 +85,10 @@ func TestResourcePrivateChildAndEvidence(t *testing.T) {
if strings.Contains(joined, "private-secret") || strings.Contains(joined, "https://") || strings.Contains(joined, "-k") || args[0] != "--disable" { if strings.Contains(joined, "private-secret") || strings.Contains(joined, "https://") || strings.Contains(joined, "-k") || args[0] != "--disable" {
t.Fatalf("unsafe argv: %v", args) t.Fatalf("unsafe argv: %v", args)
} }
if !strings.Contains(joined, "--noproxy --proxy socks5://127.0.0.1:1080") || !strings.Contains(joined, "--tlsv1.2 --tls-max 1.2") { if !strings.Contains(joined, "--noproxy --proxy socks5h://127.0.0.1:1080") || !strings.Contains(joined, "--tlsv1.2 --tls-max 1.2") {
t.Fatal("missing explicit routing/TLS") t.Fatal("missing explicit routing/TLS")
} }
assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:1080")
if !strings.Contains(joined, "--http1.1 --raw") || !strings.Contains(joined, "--suppress-connect-headers") { if !strings.Contains(joined, "--http1.1 --raw") || !strings.Contains(joined, "--suppress-connect-headers") {
t.Fatal("missing native HTTP/1.1 raw contract") t.Fatal("missing native HTTP/1.1 raw contract")
} }
@@ -247,6 +249,7 @@ func TestResourceDiscoveryAndMedia(t *testing.T) {
} }
for _, mode := range []string{"media", "bad-range", "root"} { for _, mode := range []string{"media", "bad-range", "root"} {
runner := func(_ context.Context, args []string, _ io.Reader, out, diagnostic io.Writer) error { runner := func(_ context.Context, args []string, _ io.Reader, out, diagnostic io.Writer) error {
assertManagedDNSArgs(t, args, "socks5h://127.0.0.1:1080")
if !strings.Contains(strings.Join(args, " "), "--range 0-65535") { if !strings.Contains(strings.Join(args, " "), "--range 0-65535") {
t.Fatal("missing bounded range") t.Fatal("missing bounded range")
} }
+7 -2
View File
@@ -104,8 +104,13 @@ without echoing input. DNS applies only to this target's native `ss-server`.
The image build checks installed `ss-server -h` for native `-d <addr>` support; The image build checks installed `ss-server -h` for native `-d <addr>` support;
the validated nonsecret address is passed as a separate `-d` argv value, not the validated nonsecret address is passed as a separate `-d` argv value, not
eval or an assumed JSON key. Passwords still go only to private JSON configs. eval or an assumed JSON key. Passwords still go only to private JSON configs.
The reported `8.8.8.8` diagnostic corrected a tampered avatar response, but does Managed probes use `socks5h://127.0.0.1:1080`: Player, metadata, image,
not fix/prove all thumbnail routes. Native DNS correction is **not full asset media, recovery and warmup hostnames go through the owned SS listener rather than
curl's local DNS. Older private `socks5` overrides are validated and canonicalized
internally; credentials and unowned endpoints remain forbidden. Public legacy
discovery and root checker local `--resolve` pinning are unchanged.
This corrects a DNS path bypass, not a proven cause of earlier peer certificate
failures, and does not fix/prove all thumbnail routes. It is **not full asset
availability proof**. No DoH bridge, permanent Google IP pins or global host DNS availability proof**. No DoH bridge, permanent Google IP pins or global host DNS
changes are supplied. PID 1 remains the sole startup/recovery owner. changes are supplied. PID 1 remains the sole startup/recovery owner.
+2 -1
View File
@@ -27,7 +27,7 @@ with tempfile.TemporaryDirectory(prefix='target-config-') as tmp:
ZAPRET_AUTOTUNE_YOUTUBE_SERVICE='0', ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE='cold', ZAPRET_AUTOTUNE_YOUTUBE_SERVICE='0', ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE='cold',
ZAPRET_AUTOTUNE_VIDEO_ID='dQw4w9WgXcQ', ZAPRET_AUTOTUNE_VIDEO_ID='dQw4w9WgXcQ',
ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS='["dQw4w9WgXcQ"]', ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS='["dQw4w9WgXcQ"]',
ZAPRET_AUTOTUNE_SOCKS_PROXY='socks5://127.0.0.1:1080') ZAPRET_AUTOTUNE_SOCKS_PROXY='socks5h://127.0.0.1:1080')
for dns, valid in (('', True), ('8.8.8.8', True), ('2001:4860:4860::8888', True), for dns, valid in (('', True), ('8.8.8.8', True), ('2001:4860:4860::8888', True),
('example.org', False), ('8.8.8.8\n', False), ('-d 8.8.8.8', False)): ('example.org', False), ('8.8.8.8\n', False), ('-d 8.8.8.8', False)):
for path in private.iterdir(): for path in private.iterdir():
@@ -62,4 +62,5 @@ with tempfile.TemporaryDirectory(prefix='target-config-') as tmp:
assert settings['ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE'] == mode assert settings['ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE'] == mode
assert json.loads(settings['ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS']) == ids assert json.loads(settings['ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS']) == ids
assert settings['SS_DNS_SERVER'] == overrides.get('SS_DNS_SERVER', '') assert settings['SS_DNS_SERVER'] == overrides.get('SS_DNS_SERVER', '')
assert settings['ZAPRET_AUTOTUNE_SOCKS_PROXY'] == 'socks5h://127.0.0.1:1080'
print('target config fixtures passed') print('target config fixtures passed')
+1
View File
@@ -15,6 +15,7 @@ assert " image: ${ZAPRET_AUTOTUNE_IMAGE:-zapret-autotune-managed-target:local
assert " cap_drop: [ALL]\n" in compose assert " cap_drop: [ALL]\n" in compose
assert " cap_add: [NET_ADMIN, NET_RAW, SETUID, SETGID, KILL, SYS_PTRACE]\n" in compose assert " cap_add: [NET_ADMIN, NET_RAW, SETUID, SETGID, KILL, SYS_PTRACE]\n" in compose
assert "pid:" not in compose # Keep inspection confined to the private PID namespace. assert "pid:" not in compose # Keep inspection confined to the private PID namespace.
assert 'ZAPRET_AUTOTUNE_SOCKS_PROXY: socks5h://127.0.0.1:1080' in compose
assert compose.count(" - type: bind\n") == 1 assert compose.count(" - type: bind\n") == 1
assert " source: ./target-state\n" in compose assert " source: ./target-state\n" in compose
assert " target: /var/lib/zapret-autotune/target\n" in compose assert " target: /var/lib/zapret-autotune/target\n" in compose
+1 -1
View File
@@ -22,7 +22,7 @@ services:
ZAPRET_AUTOTUNE_TARGET_ID: zapret-autotune-managed-v1 ZAPRET_AUTOTUNE_TARGET_ID: zapret-autotune-managed-v1
ZAPRET_AUTOTUNE_TARGET_DIR: /var/lib/zapret-autotune/target ZAPRET_AUTOTUNE_TARGET_DIR: /var/lib/zapret-autotune/target
ZAPRET_CONFIG: /var/lib/zapret-autotune/target/config ZAPRET_CONFIG: /var/lib/zapret-autotune/target/config
ZAPRET_AUTOTUNE_SOCKS_PROXY: socks5://127.0.0.1:1080 ZAPRET_AUTOTUNE_SOCKS_PROXY: socks5h://127.0.0.1:1080
ZAPRET_AUTOTUNE_DB: /var/lib/zapret-autotune/target/candidates.db ZAPRET_AUTOTUNE_DB: /var/lib/zapret-autotune/target/candidates.db
ports: ports:
- "127.0.0.1:${ZAPRET_AUTOTUNE_HOST_SOCKS_PORT:-11080}:1080/tcp" - "127.0.0.1:${ZAPRET_AUTOTUNE_HOST_SOCKS_PORT:-11080}:1080/tcp"