From c49e71934b7fd38166016dec8afaff2470092741 Mon Sep 17 00:00:00 2001 From: Gravirei Date: Sat, 28 Nov 2026 03:08:42 +0600 Subject: [PATCH 1/4] 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/4] 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/4] 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/4] 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]", ]