From c49e71934b7fd38166016dec8afaff2470092741 Mon Sep 17 00:00:00 2001 From: Gravirei Date: Sat, 28 Nov 2026 03:08:42 +0600 Subject: [PATCH 1/9] fix(node): use libcurl-compatible DNS pins for upstream mirror (#619) Drop the leading '+' from the http.curloptResolve pin. The expiring-entry form requires libcurl 7.75; older versions parse the '+' as part of the hostname, ignore the pin, and re-resolve at connect time. This reopens the DNS rebinding window the pin exists to close for owner-selected upstream URLs. Build the pin through a resolve_pin() helper that matches the sync worker's peer pin, and add tests for the generated pin and the hardened git config. --- crates/twigpine-node/src/upstream_mirror.rs | 58 ++++++++++++++++----- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index 813c94fed..0f5255968 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -70,17 +70,9 @@ impl EgressPolicy { let addresses: Vec = addresses.into_iter().collect(); self.validate_addresses(&policy_host, &addresses)?; - let pinned = addresses - .iter() - .map(|ip| match ip { - IpAddr::V4(v4) => v4.to_string(), - IpAddr::V6(v6) => format!("[{v6}]"), - }) - .collect::>() - .join(","); Ok(PinnedUpstream { url: url.to_string(), - curlopt_resolve: Some(format!("+{connect_host}:{port}:{pinned}")), + curlopt_resolve: Some(resolve_pin(&connect_host, port, addresses)), }) } @@ -99,6 +91,24 @@ impl EgressPolicy { } } +/// The `http.curloptResolve` entry pinning `host:port` to `addrs`. +/// There is deliberately no `+` prefix: that expiring-entry form arrived in +/// libcurl 7.75, and an older libcurl reads the `+` as part of the hostname, +/// so the entry never matches and git falls back to DNS at connect time. The +/// worker's Git 2.37 floor does not imply a libcurl that understands `+`. +fn resolve_pin(host: &str, port: u16, mut addrs: Vec) -> String { + addrs.sort_unstable(); + let list = addrs + .iter() + .map(|ip| match ip { + IpAddr::V4(v4) => v4.to_string(), + IpAddr::V6(v6) => format!("[{v6}]"), + }) + .collect::>() + .join(","); + format!("{host}:{port}:{list}") +} + fn normalize_policy_host(host: &str) -> String { host.trim_end_matches('.').to_ascii_lowercase() } @@ -684,6 +694,25 @@ esac assert!((2, 36) < MIN_CURL_OPT_RESOLVE_GIT); } + #[test] + fn resolve_pin_is_honored_by_libcurl_older_than_75() { + // A leading `+` is parsed as part of the hostname until libcurl 7.75, + // so the pin never matches and git re-resolves at connect time. + let pin = resolve_pin( + "github.example", + 443, + vec![ + "2606:4700:4700::1111".parse().unwrap(), + "8.8.8.8".parse().unwrap(), + ], + ); + assert_eq!(pin, "github.example:443:8.8.8.8,[2606:4700:4700::1111]"); + assert!(!pin.starts_with('+')); + + let single = resolve_pin("forge.example", 8080, vec!["8.8.4.4".parse().unwrap()]); + assert_eq!(single, "forge.example:8080:8.8.4.4"); + } + #[test] fn every_resolved_address_must_be_public() { let policy = EgressPolicy; @@ -753,7 +782,7 @@ esac fn fetch_command_pins_dns_and_only_updates_branches_and_tags() { let upstream = PinnedUpstream { url: "https://github.example/org/repo.git".to_string(), - curlopt_resolve: Some("+github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string()), + curlopt_resolve: Some("github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string()), }; let command = fetch_command(&upstream); let has_config = |key: &str, value: &str| { @@ -769,7 +798,7 @@ esac assert!(has_config("http.sslVerify", "true")); assert!(has_config( "http.curloptResolve", - "+github.example:443:8.8.8.8,[2606:4700:4700::1111]" + "github.example:443:8.8.8.8,[2606:4700:4700::1111]" )); assert!(has_config( "http.https://github.example/org/repo.git.followRedirects", @@ -785,8 +814,13 @@ esac )); assert!(has_config( "http.https://github.example/org/repo.git.curloptResolve", - "+github.example:443:8.8.8.8,[2606:4700:4700::1111]" + "github.example:443:8.8.8.8,[2606:4700:4700::1111]" )); + assert!(command + .config + .iter() + .filter(|(key, value)| key.ends_with("curloptResolve") && !value.is_empty()) + .all(|(_, value)| !value.starts_with('+'))); assert!(has_config( "credential.https://github.example/org/repo.git.helper", "" From db09442d1efdb8eb8a4c58ec8a26e46dbcc48825 Mon Sep 17 00:00:00 2001 From: Gravirei Date: Sat, 28 Nov 2026 03:08:42 +0600 Subject: [PATCH 2/9] chore(node): silence macro-generated double_must_use on BlockStore The async_trait macro adds #[must_use] to the boxed futures it generates, which clippy 1.99 flags as double_must_use. Scope an allow to the trait with an explanation; no behavior change. --- crates/twigpine-node/src/blockstore/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/twigpine-node/src/blockstore/mod.rs b/crates/twigpine-node/src/blockstore/mod.rs index 0d19f577d..d5052eeb3 100644 --- a/crates/twigpine-node/src/blockstore/mod.rs +++ b/crates/twigpine-node/src/blockstore/mod.rs @@ -111,6 +111,11 @@ pub enum BlockStoreError { Backend(String), } +// `#[async_trait]` puts `#[must_use]` on the boxed futures it generates, which +// clippy 1.99 reports as `double_must_use` on the already-must-use futures. +// The attribute is macro-generated, so silence it here rather than in the +// trait's method signatures. +#[allow(clippy::double_must_use)] #[async_trait] pub trait BlockStore: Send + Sync { /// Stream `body` into the store under `id`, hashing as it goes. The body From 049039f2018be7080b17eb682fd5cac5a7ad3b1f Mon Sep 17 00:00:00 2001 From: Gravirei Date: Sat, 28 Nov 2026 08:48:50 +0600 Subject: [PATCH 3/9] fix(node): keep upstream mirror pins valid before libcurl 7.59 (#619) A comma-separated CURLOPT_RESOLVE address list needs libcurl 7.59. Older libcurl rejects the whole entry and re-resolves at connect time, reopening the rebinding window the pin exists to close. Emit a single checked address first, then the full comma-separated list. Older libcurl keeps the valid single pin; versions that override a cached host:port entry keep every validated address. No path falls back to connect-time DNS, and single-address behavior is unchanged. --- crates/twigpine-node/src/upstream_mirror.rs | 101 ++++++++++++++------ 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index 0f5255968..8b2093045 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -30,7 +30,7 @@ struct EgressPolicy; #[derive(Debug, Clone, PartialEq, Eq)] struct PinnedUpstream { url: String, - curlopt_resolve: Option, + curlopt_resolve: Vec, } impl EgressPolicy { @@ -52,7 +52,7 @@ impl EgressPolicy { url: url.to_string(), // An IP literal performs no DNS lookup, so there is no rebinding // window to pin. TLS still verifies the literal from the URL. - curlopt_resolve: None, + curlopt_resolve: Vec::new(), }); } @@ -72,7 +72,7 @@ impl EgressPolicy { Ok(PinnedUpstream { url: url.to_string(), - curlopt_resolve: Some(resolve_pin(&connect_host, port, addresses)), + curlopt_resolve: resolve_pins(&connect_host, port, addresses), }) } @@ -91,22 +91,35 @@ impl EgressPolicy { } } -/// The `http.curloptResolve` entry pinning `host:port` to `addrs`. +/// The `http.curloptResolve` entries pinning `host:port` to `addrs`. +/// /// There is deliberately no `+` prefix: that expiring-entry form arrived in /// libcurl 7.75, and an older libcurl reads the `+` as part of the hostname, /// so the entry never matches and git falls back to DNS at connect time. The /// worker's Git 2.37 floor does not imply a libcurl that understands `+`. -fn resolve_pin(host: &str, port: u16, mut addrs: Vec) -> String { +/// +/// A comma-separated address list needs libcurl 7.59; older versions reject +/// the whole entry and would re-resolve at connect time. Emit a single checked +/// address first: on those versions it is the only accepted entry, so the +/// connection stays pinned to a validated address. Versions that override an +/// existing host:port entry then replace it with the full list, keeping every +/// validated address. The single entry is therefore only a fallback, never a +/// path to connect-time DNS. +fn resolve_pins(host: &str, port: u16, mut addrs: Vec) -> Vec { addrs.sort_unstable(); - let list = addrs + let formatted = addrs .iter() .map(|ip| match ip { IpAddr::V4(v4) => v4.to_string(), IpAddr::V6(v6) => format!("[{v6}]"), }) - .collect::>() - .join(","); - format!("{host}:{port}:{list}") + .collect::>(); + let mut pins = Vec::with_capacity(2); + if formatted.len() > 1 { + pins.push(format!("{host}:{port}:{}", formatted[0])); + } + pins.push(format!("{host}:{port}:{}", formatted.join(","))); + pins } fn normalize_policy_host(host: &str) -> String { @@ -206,10 +219,10 @@ fn fetch_command(upstream: &PinnedUpstream) -> FetchCommand { (http_scope("saveCookies"), "false".to_string()), (http_scope("sslVerify"), "true".to_string()), ]; - if let Some(resolve) = &upstream.curlopt_resolve { + for pin in &upstream.curlopt_resolve { config.extend([ - ("http.curloptResolve".to_string(), resolve.clone()), - (http_scope("curloptResolve"), resolve.clone()), + ("http.curloptResolve".to_string(), pin.clone()), + (http_scope("curloptResolve"), pin.clone()), ]); } config.extend([ @@ -695,10 +708,11 @@ esac } #[test] - fn resolve_pin_is_honored_by_libcurl_older_than_75() { - // A leading `+` is parsed as part of the hostname until libcurl 7.75, - // so the pin never matches and git re-resolves at connect time. - let pin = resolve_pin( + fn resolve_pins_work_on_libcurl_before_75_and_59() { + // No leading `+`: it is parsed as part of the hostname before libcurl + // 7.75. A single checked address comes first so libcurl before 7.59, + // which rejects the comma-separated list, still has a valid pin. + let pins = resolve_pins( "github.example", 443, vec![ @@ -706,11 +720,17 @@ esac "8.8.8.8".parse().unwrap(), ], ); - assert_eq!(pin, "github.example:443:8.8.8.8,[2606:4700:4700::1111]"); - assert!(!pin.starts_with('+')); + assert_eq!( + pins, + vec![ + "github.example:443:8.8.8.8".to_string(), + "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), + ] + ); + assert!(pins.iter().all(|pin| !pin.starts_with('+'))); - let single = resolve_pin("forge.example", 8080, vec!["8.8.4.4".parse().unwrap()]); - assert_eq!(single, "forge.example:8080:8.8.4.4"); + let single = resolve_pins("forge.example", 8080, vec!["8.8.4.4".parse().unwrap()]); + assert_eq!(single, vec!["forge.example:8080:8.8.4.4".to_string()]); } #[test] @@ -782,7 +802,10 @@ esac fn fetch_command_pins_dns_and_only_updates_branches_and_tags() { let upstream = PinnedUpstream { url: "https://github.example/org/repo.git".to_string(), - curlopt_resolve: Some("github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string()), + curlopt_resolve: vec![ + "github.example:443:8.8.8.8".to_string(), + "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), + ], }; let command = fetch_command(&upstream); let has_config = |key: &str, value: &str| { @@ -790,16 +813,29 @@ esac .config .contains(&(key.to_string(), value.to_string())) }; + let pins_for = |key: &str| -> Vec<&str> { + command + .config + .iter() + .filter(|(config_key, value)| config_key == key && !value.is_empty()) + .map(|(_, value)| value.as_str()) + .collect() + }; assert!(has_config("http.followRedirects", "false")); assert!(has_config("http.proxy", "")); assert!(has_config("http.extraHeader", "")); assert!(has_config("http.cookieFile", "")); assert!(has_config("http.saveCookies", "false")); assert!(has_config("http.sslVerify", "true")); - assert!(has_config( - "http.curloptResolve", - "github.example:443:8.8.8.8,[2606:4700:4700::1111]" - )); + // The single-address fallback must come first: older libcurl keeps the + // first entry, while newer libcurl replaces it with the full list. + assert_eq!( + pins_for("http.curloptResolve"), + vec![ + "github.example:443:8.8.8.8", + "github.example:443:8.8.8.8,[2606:4700:4700::1111]", + ] + ); assert!(has_config( "http.https://github.example/org/repo.git.followRedirects", "false" @@ -812,10 +848,13 @@ esac "http.https://github.example/org/repo.git.extraHeader", "" )); - assert!(has_config( - "http.https://github.example/org/repo.git.curloptResolve", - "github.example:443:8.8.8.8,[2606:4700:4700::1111]" - )); + assert_eq!( + pins_for("http.https://github.example/org/repo.git.curloptResolve"), + vec![ + "github.example:443:8.8.8.8", + "github.example:443:8.8.8.8,[2606:4700:4700::1111]", + ] + ); assert!(command .config .iter() @@ -956,7 +995,7 @@ esac }); let upstream = PinnedUpstream { url: format!("https://127.0.0.1:{port}/org/repo=mirror.git"), - curlopt_resolve: None, + curlopt_resolve: Vec::new(), }; let error = run_fetch( "git", @@ -982,7 +1021,7 @@ esac .resolve(reqwest::Url::parse("https://8.8.8.8/org/repo.git").unwrap()) .await .unwrap(); - assert_eq!(allowed.curlopt_resolve, None); + assert!(allowed.curlopt_resolve.is_empty()); for denied in [ "127.0.0.1", From 628a1e5599597b28a713353d88cf7b171a44f6aa Mon Sep 17 00:00:00 2001 From: Gravirei Date: Sat, 28 Nov 2026 10:40:46 +0600 Subject: [PATCH 4/9] fix(node): pin every checked address across libcurl duplicate semantics (#619) libcurl 7.59 and 7.60 keep the first duplicate host:port resolve entry, while 7.61+ keep the last. A two-entry pin therefore covered all checked addresses only on the newer versions. Emit the full comma-separated list at both ends with a single checked address in the middle: pre-7.59 rejects the lists and keeps the single pin, 7.59/7.60 keep the first list, and 7.61+ keep the last. Every generation pins a validated address and none can fall back to connect-time DNS. --- crates/twigpine-node/src/upstream_mirror.rs | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index 8b2093045..99fd66087 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -99,12 +99,12 @@ impl EgressPolicy { /// worker's Git 2.37 floor does not imply a libcurl that understands `+`. /// /// A comma-separated address list needs libcurl 7.59; older versions reject -/// the whole entry and would re-resolve at connect time. Emit a single checked -/// address first: on those versions it is the only accepted entry, so the -/// connection stays pinned to a validated address. Versions that override an -/// existing host:port entry then replace it with the full list, keeping every -/// validated address. The single entry is therefore only a fallback, never a -/// path to connect-time DNS. +/// the whole entry and would re-resolve at connect time. Duplicate host:port +/// entries also have opposite semantics: libcurl 7.59/7.60 keep the first one, +/// while 7.61+ keep the last. Emit the full list at both ends with a single +/// checked address in the middle, so each generation keeps a valid pin: +/// pre-7.59 rejects both lists and keeps the single address, 7.59/7.60 keep +/// the first list, and 7.61+ keep the last. None can fall back to DNS. fn resolve_pins(host: &str, port: u16, mut addrs: Vec) -> Vec { addrs.sort_unstable(); let formatted = addrs @@ -114,11 +114,13 @@ fn resolve_pins(host: &str, port: u16, mut addrs: Vec) -> Vec { IpAddr::V6(v6) => format!("[{v6}]"), }) .collect::>(); - let mut pins = Vec::with_capacity(2); + let full = format!("{host}:{port}:{}", formatted.join(",")); + let mut pins = Vec::with_capacity(3); if formatted.len() > 1 { + pins.push(full.clone()); pins.push(format!("{host}:{port}:{}", formatted[0])); } - pins.push(format!("{host}:{port}:{}", formatted.join(","))); + pins.push(full); pins } @@ -708,10 +710,11 @@ esac } #[test] - fn resolve_pins_work_on_libcurl_before_75_and_59() { + fn resolve_pins_work_across_libcurl_duplicate_semantics() { // No leading `+`: it is parsed as part of the hostname before libcurl - // 7.75. A single checked address comes first so libcurl before 7.59, - // which rejects the comma-separated list, still has a valid pin. + // 7.75. The full list is repeated at both ends so first-wins (7.59/ + // 7.60) and last-wins (7.61+) libcurl both keep every checked address; + // the single address in the middle is what pre-7.59 keeps. let pins = resolve_pins( "github.example", 443, @@ -723,6 +726,7 @@ esac assert_eq!( pins, vec![ + "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), "github.example:443:8.8.8.8".to_string(), "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), ] @@ -803,6 +807,7 @@ esac let upstream = PinnedUpstream { url: "https://github.example/org/repo.git".to_string(), curlopt_resolve: vec![ + "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), "github.example:443:8.8.8.8".to_string(), "github.example:443:8.8.8.8,[2606:4700:4700::1111]".to_string(), ], @@ -827,11 +832,12 @@ esac assert!(has_config("http.cookieFile", "")); assert!(has_config("http.saveCookies", "false")); assert!(has_config("http.sslVerify", "true")); - // The single-address fallback must come first: older libcurl keeps the - // first entry, while newer libcurl replaces it with the full list. + // The full list is first and last so both duplicate-entry generations + // keep it; pre-7.59 libcurl rejects those and keeps the single pin. assert_eq!( pins_for("http.curloptResolve"), vec![ + "github.example:443:8.8.8.8,[2606:4700:4700::1111]", "github.example:443:8.8.8.8", "github.example:443:8.8.8.8,[2606:4700:4700::1111]", ] @@ -851,6 +857,7 @@ esac assert_eq!( pins_for("http.https://github.example/org/repo.git.curloptResolve"), vec![ + "github.example:443:8.8.8.8,[2606:4700:4700::1111]", "github.example:443:8.8.8.8", "github.example:443:8.8.8.8,[2606:4700:4700::1111]", ] From 6cdfb37595f4e22933e7afe11452fce25a9d847a Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:19:52 -0600 Subject: [PATCH 5/9] fix(node): write the single-address mirror pin without IPv6 brackets (#619) libcurl before 7.57 rejects a bracketed address in CURLOPT_RESOLVE, so an upstream that resolves only to IPv6 addresses got no pin from any of the three entries and libcurl re-resolved the host at connect time. A bare IPv6 address is accepted in a single-address entry by every libcurl version, so the middle entry and the lone entry for a one-address answer now use it. The comma lists keep brackets, since only 7.59+ reads them. --- crates/twigpine-node/src/upstream_mirror.rs | 60 +++++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index 99fd66087..ead06d3b2 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -91,7 +91,8 @@ impl EgressPolicy { } } -/// The `http.curloptResolve` entries pinning `host:port` to `addrs`. +/// The `http.curloptResolve` entries pinning `host:port` to `addrs`, the +/// validated answer set, which [`EgressPolicy::resolve`] never passes empty. /// /// There is deliberately no `+` prefix: that expiring-entry form arrived in /// libcurl 7.75, and an older libcurl reads the `+` as part of the hostname, @@ -105,23 +106,27 @@ impl EgressPolicy { /// checked address in the middle, so each generation keeps a valid pin: /// pre-7.59 rejects both lists and keeps the single address, 7.59/7.60 keep /// the first list, and 7.61+ keep the last. None can fall back to DNS. +/// +/// The single-address entry writes an IPv6 address without brackets: libcurl +/// before 7.57 rejects `[addr]`, which would leave an IPv6-only answer with no +/// pin, and every version accepts the bare form in a single-address entry. The +/// lists keep brackets because only 7.59+ reads them. fn resolve_pins(host: &str, port: u16, mut addrs: Vec) -> Vec { addrs.sort_unstable(); - let formatted = addrs + let single = format!("{host}:{port}:{}", addrs[0]); + if addrs.len() == 1 { + return vec![single]; + } + let list = addrs .iter() .map(|ip| match ip { IpAddr::V4(v4) => v4.to_string(), IpAddr::V6(v6) => format!("[{v6}]"), }) - .collect::>(); - let full = format!("{host}:{port}:{}", formatted.join(",")); - let mut pins = Vec::with_capacity(3); - if formatted.len() > 1 { - pins.push(full.clone()); - pins.push(format!("{host}:{port}:{}", formatted[0])); - } - pins.push(full); - pins + .collect::>() + .join(","); + let full = format!("{host}:{port}:{list}"); + vec![full.clone(), single, full] } fn normalize_policy_host(host: &str) -> String { @@ -737,6 +742,39 @@ esac assert_eq!(single, vec!["forge.example:8080:8.8.4.4".to_string()]); } + #[test] + fn resolve_pins_keep_an_ipv6_only_answer_pinned_before_libcurl_7_57() { + // libcurl before 7.57 rejects `[addr]`, so a bracketed single entry + // leaves an IPv6-only answer with no pin at all. Every version accepts + // a bare IPv6 address in a single-address entry. + let pins = resolve_pins( + "v6.example", + 443, + vec![ + "2606:4700:4700::1111".parse().unwrap(), + "2606:4700:4700::1001".parse().unwrap(), + ], + ); + assert_eq!( + pins, + vec![ + "v6.example:443:[2606:4700:4700::1001],[2606:4700:4700::1111]".to_string(), + "v6.example:443:2606:4700:4700::1001".to_string(), + "v6.example:443:[2606:4700:4700::1001],[2606:4700:4700::1111]".to_string(), + ] + ); + + let single = resolve_pins( + "v6.example", + 443, + vec!["2606:4700:4700::1111".parse().unwrap()], + ); + assert_eq!( + single, + vec!["v6.example:443:2606:4700:4700::1111".to_string()] + ); + } + #[test] fn every_resolved_address_must_be_public() { let policy = EgressPolicy; From cfab3364689ddb5bcd5f4e6460f0279c6b1a3a4f Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:58:02 -0600 Subject: [PATCH 6/9] test(node): check each mirror resolver reset precedes its pins An empty http.curloptResolve value clears git's multi-valued list, so a reset that lands after the pin entries drops every pin. The fetch_command test filtered empty values out before comparing, which kept it green under that reorder. It now checks that each scope is reset exactly once and before its first pin. --- crates/twigpine-node/src/upstream_mirror.rs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index ead06d3b2..d418e4143 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -905,6 +905,34 @@ esac .iter() .filter(|(key, value)| key.ends_with("curloptResolve") && !value.is_empty()) .all(|(_, value)| !value.starts_with('+'))); + // An empty value clears git's multi-valued resolver list, so each + // scope's reset must come before that scope's first pin or it would + // silently drop every pin. + for key in [ + "http.curloptResolve", + "http.https://github.example/org/repo.git.curloptResolve", + ] { + let position = |want_empty: bool| { + command + .config + .iter() + .position(|(k, v)| k == key && v.is_empty() == want_empty) + .unwrap_or_else(|| panic!("{key} entry missing")) + }; + assert!( + position(true) < position(false), + "{key} reset must precede its pins" + ); + assert_eq!( + command + .config + .iter() + .filter(|(k, v)| k == key && v.is_empty()) + .count(), + 1, + "{key} must be reset exactly once" + ); + } assert!(has_config( "credential.https://github.example/org/repo.git.helper", "" From d949a4d3298e69fa418d755a402fc3ed7f282234 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:58:02 -0600 Subject: [PATCH 7/9] chore(node): drop the BlockStore double_must_use allow The CI clippy job (stable, currently 1.100) is clean on main without it, so the allow suppresses nothing the gate reports and this change stays limited to the mirror DNS pin. --- crates/twigpine-node/src/blockstore/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/twigpine-node/src/blockstore/mod.rs b/crates/twigpine-node/src/blockstore/mod.rs index d5052eeb3..0d19f577d 100644 --- a/crates/twigpine-node/src/blockstore/mod.rs +++ b/crates/twigpine-node/src/blockstore/mod.rs @@ -111,11 +111,6 @@ pub enum BlockStoreError { Backend(String), } -// `#[async_trait]` puts `#[must_use]` on the boxed futures it generates, which -// clippy 1.99 reports as `double_must_use` on the already-must-use futures. -// The attribute is macro-generated, so silence it here rather than in the -// trait's method signatures. -#[allow(clippy::double_must_use)] #[async_trait] pub trait BlockStore: Send + Sync { /// Stream `body` into the store under `id`, hashing as it goes. The body From 599191ae6a9912fd7f28fbf9b78678f751efe4e2 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 28 Nov 2026 13:00:11 -0600 Subject: [PATCH 8/9] test(node): prove real git dials the pinned mirror address Every existing pin test compared strings. This one points the fetch at pin.invalid, which has no DNS answer, with resolver entries for a loopback listener, so the listener is reachable only if git and libcurl honor the pins. The two-address case binds the second address, which fails unless libcurl kept the full list rather than the single lowest address. --- crates/twigpine-node/src/upstream_mirror.rs | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index d418e4143..e52efc6ea 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -1035,6 +1035,65 @@ esac assert!(error.to_string().contains("network or credential")); } + #[cfg(unix)] + #[test] + fn real_git_dials_the_pinned_address_for_an_unresolvable_host() { + // `pin.invalid` has no DNS answer, so the listener is reachable only + // through the resolver entries the fetch config carries. A pin that git + // or libcurl ignores falls back to DNS and the listener sees nothing. + // The two-address case binds the second address, so it passes only if + // libcurl kept the full list rather than the single lowest address + // (libcurl 7.59+; older versions keep the single entry by design). + for (bind, pinned) in [ + ("127.0.0.1", vec!["127.0.0.1"]), + ("127.0.0.2", vec!["127.0.0.1", "127.0.0.2"]), + ] { + let repo = tempfile::tempdir().unwrap(); + let init = fixture_git(repo.path()) + .args(["init", "--bare"]) + .output() + .unwrap(); + assert!(init.status.success()); + + let listener = std::net::TcpListener::bind((bind, 0)).unwrap(); + let port = listener.local_addr().unwrap().port(); + listener.set_nonblocking(true).unwrap(); + let accepted = std::thread::spawn(move || { + let deadline = Instant::now() + Duration::from_secs(3); + while Instant::now() < deadline { + match listener.accept() { + Ok(_) => return true, + Err(error) if error.kind() == std::io::ErrorKind::WouldBlock => { + std::thread::sleep(Duration::from_millis(10)); + } + Err(error) => panic!("accepting pinned-Git transport probe: {error}"), + } + } + false + }); + let upstream = PinnedUpstream { + url: format!("https://pin.invalid:{port}/org/repo.git"), + curlopt_resolve: resolve_pins( + "pin.invalid", + port, + pinned.iter().map(|ip| ip.parse().unwrap()).collect(), + ), + }; + let error = run_fetch( + "git", + repo.path(), + &upstream, + Duration::from_secs(5), + Instant::now() + Duration::from_secs(600), + ) + .unwrap_err(); + assert!( + accepted.join().unwrap(), + "real Git must dial the pinned {bind} for pin.invalid; got {error:#}" + ); + } + } + #[cfg(unix)] #[test] fn hardened_real_git_reaches_https_transport_for_equals_path() { From 51c2c4a2517ff338e28ab56979516d27ee36c09c Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sat, 28 Nov 2026 13:00:28 -0600 Subject: [PATCH 9/9] docs(node): state the non-empty precondition on resolve_pins as a caller duty --- crates/twigpine-node/src/upstream_mirror.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/twigpine-node/src/upstream_mirror.rs b/crates/twigpine-node/src/upstream_mirror.rs index e52efc6ea..11ca47898 100644 --- a/crates/twigpine-node/src/upstream_mirror.rs +++ b/crates/twigpine-node/src/upstream_mirror.rs @@ -92,7 +92,9 @@ impl EgressPolicy { } /// The `http.curloptResolve` entries pinning `host:port` to `addrs`, the -/// validated answer set, which [`EgressPolicy::resolve`] never passes empty. +/// validated answer set. Callers must pass a non-empty set; nothing here +/// checks it, and [`EgressPolicy::resolve`], the only caller, refuses an empty +/// answer before calling. /// /// There is deliberately no `+` prefix: that expiring-entry form arrived in /// libcurl 7.75, and an older libcurl reads the `+` as part of the hostname,