From 47016e1951b470a92bfd42602b5c02b2ac50c9ae Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:17:26 -0600 Subject: [PATCH 1/5] fix(node): move the encrypted-blob serve onto AppState::client_key #640 merged onto a base before #634, leaving the encrypted-blob serve and shared git read path on the removed Option-based rate-limit API. Move them to AppState::client_key and carry the trusted proxy peer list in the route limiter. --- crates/twigpine-node/src/api/encrypted.rs | 27 +++++++++-------------- crates/twigpine-node/src/api/repos.rs | 4 ++-- crates/twigpine-node/src/server.rs | 1 + 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/crates/twigpine-node/src/api/encrypted.rs b/crates/twigpine-node/src/api/encrypted.rs index b708dda2b..436cf47d4 100644 --- a/crates/twigpine-node/src/api/encrypted.rs +++ b/crates/twigpine-node/src/api/encrypted.rs @@ -127,7 +127,7 @@ pub async fn get_encrypted_blob( auth: Option>, Path((owner, repo, oid)): Path<(String, String, String)>, ) -> Result { - let key = crate::rate_limit::client_key(&headers, peer, state.push_limiter_trust); + let key = state.client_key(&headers, peer); let caller = auth.as_ref().map(|e| e.0 .0.as_str()); let (record, _rules) = crate::api::authorize_repo_read(&state, &owner, &repo, caller, "/").await?; @@ -144,26 +144,21 @@ pub async fn get_encrypted_blob( Ok(permit) => permit, Err(_) => { tracing::warn!("encrypted-blob serve cap reached; shedding request with 503"); - if let Some(key) = key.as_deref() { - state.encrypted_blob_rate_limiter.refund(key).await; - } + state.encrypted_blob_rate_limiter.refund(&key).await; return Err(AppError::Overloaded( "encrypted blob service at capacity, retry shortly".into(), )); } }; - let per_source = match key.as_deref() { - Some(ip) => match state.encrypted_serve_per_caller.try_acquire(ip) { - Some(permit) => Some(permit), - None => { - tracing::warn!(key = %ip, "encrypted-blob per-source serve cap reached; shedding request with 503"); - state.encrypted_blob_rate_limiter.refund(ip).await; - return Err(AppError::Overloaded( - "encrypted blob service at capacity for this source, retry shortly".into(), - )); - } - }, - None => None, + let per_source = match state.encrypted_serve_per_caller.try_acquire(&key) { + Some(permit) => Some(permit), + None => { + tracing::warn!(key = %key, "encrypted-blob per-source serve cap reached; shedding request with 503"); + state.encrypted_blob_rate_limiter.refund(&key).await; + return Err(AppError::Overloaded( + "encrypted blob service at capacity for this source, retry shortly".into(), + )); + } }; // Opaque on purpose: the error text names the node's Kubo endpoint and the // upstream status, neither of which an anonymous caller should see. diff --git a/crates/twigpine-node/src/api/repos.rs b/crates/twigpine-node/src/api/repos.rs index 5e7c32452..e128d2796 100644 --- a/crates/twigpine-node/src/api/repos.rs +++ b/crates/twigpine-node/src/api/repos.rs @@ -690,10 +690,10 @@ where T: Send + 'static, F: FnOnce(&str, &std::path::Path, std::time::Instant) -> Result + Send + 'static, { - let caller_key = read_caller_key(headers, peer, state.push_limiter_trust); + let caller_key = state.client_key(headers, peer); let caller_permit = acquire_read_caller_permit( &state.git_read_per_caller, - caller_key.as_deref(), + &caller_key, &record.name, handler, )?; diff --git a/crates/twigpine-node/src/server.rs b/crates/twigpine-node/src/server.rs index 96b7c2421..53ac2eee1 100644 --- a/crates/twigpine-node/src/server.rs +++ b/crates/twigpine-node/src/server.rs @@ -789,6 +789,7 @@ pub fn build_router(state: AppState) -> Router { let encrypted_blob_limiter = rate_limit::IpRateLimiter { limiter: state.encrypted_blob_rate_limiter.clone(), trust: state.push_limiter_trust, + trusted_peers: state.push_limiter_trusted_peers.clone(), }; let encrypted_blob_serve_routes = Router::new() .route( From 0e5c7467283833093fc494ff82aa3e319d4d0ec8 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:54:39 -0600 Subject: [PATCH 2/5] docs(node): describe the encrypted-blob per-source cap under the unknown-peer bucket Requests without a verifiable socket peer now share the reserved unknown-peer bucket under the encrypted-blob per-source cap. --- crates/twigpine-node/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/twigpine-node/src/state.rs b/crates/twigpine-node/src/state.rs index ce715f694..ee0be0122 100644 --- a/crates/twigpine-node/src/state.rs +++ b/crates/twigpine-node/src/state.rs @@ -399,7 +399,7 @@ pub struct AppState { pub encrypted_serve_semaphore: Arc, /// Per-source share of `encrypted_serve_semaphore`, keyed on the resolved /// client IP, so one source cannot hold every serve slot. A request with no - /// resolvable key is bounded by the global pool only. + /// verifiable socket peer shares the reserved unknown-peer bucket under this cap. pub encrypted_serve_per_caller: crate::rate_limit::PerCallerConcurrency, /// Per-client-IP rate brake for the encrypted-blob serve, in a bucket of its /// own: a clone fetches one envelope per withheld blob, so sharing the hourly From 49ceb101b05c2278558bee3a4c1da795e2cfc2ec Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:01:07 -0600 Subject: [PATCH 3/5] fix(deps): bump curve25519-dalek 5.0.0 to 5.1.0 for RUSTSEC-2026-0620 This lockfile-only update fixes the 5.x copy reached through ed25519-dalek 3 and libp2p-identity. The remaining 4.1.3 copy is handled separately by an audit ignore in the next commit. --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5416182d1..2a27f0226 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2534,9 +2534,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "5.0.0" +version = "5.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eed333089e2e1c1ac8c6c0398e5e2497b4c9926ca6d0365ed1e099afa5bc23" +checksum = "94c1aa5a9b7626ed65ac0cf5ea9d4f1547af89017fbac20bd4de40022fff516f" dependencies = [ "cfg-if", "cpufeatures 0.3.1", @@ -2994,7 +2994,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ebaa1a2bf1290ab3bfe5a7b771d050ebffab2711c19a81691c683a5144a25de" dependencies = [ - "curve25519-dalek 5.0.0", + "curve25519-dalek 5.1.0", "ed25519 3.0.0", "sha2 0.11.1", "subtle", From dda8c8aa5de0c39598994c116b9ffd3a793e6d70 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:02:11 -0600 Subject: [PATCH 4/5] ci(audit): waive RUSTSEC-2026-0620 for curve25519-dalek 4.1.3 and guard the waiver The remaining 4.1.3 copy is waived because its vulnerable AVX-512 backend is not reachable on the stable toolchains used here and no compatible 4.x fix exists. The weekly drift guard fails if the locked curve25519-dalek versions move while the ignore remains. --- .cargo/audit.toml | 20 ++++++++++++++++++++ .github/workflows/audit-schedule.yml | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/.cargo/audit.toml b/.cargo/audit.toml index 1d9efdee9..0e186fc90 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -70,4 +70,24 @@ ignore = [ # sqlx is ever built with the `sqlite` feature or any other libsqlite3-sys # consumer enters the build. "RUSTSEC-2026-0459", # libsqlite3-sys bundled SQLite CVE (not linked in our build) + + # curve25519-dalek 4.1.3 (AVX-512 backend scalar-multiplication arithmetic + # bug; RUSTSEC-2026-0620, upstream dalek-cryptography/curve25519-dalek#934). + # Reached through ed25519-dalek 2.2.0 and crypto_box 0.9.1 (twigpine-core, + # twigpine-attest, twigpine-cli, twigpine-node). Only 5.1.0 is patched and + # nothing on the 4.x line is, and crypto_box has no stable release after + # 0.9.1 that could move us to dalek 5 (verified 2026-11-30: only + # 0.10.0-pre.0 exists). NOT REACHABLE in our builds: on 4.0.0 to 4.1.3 the + # AVX-512 backend needs a nightly compiler, and every build and CI path here + # uses stable Rust (Dockerfile and Dockerfile.bins pin rust:1.91; CI uses + # stable, 1.91 and beta; no RUSTFLAGS, target-cpu or nightly anywhere in the + # repo). Impact if it were reachable is incorrect scalar-multiplication + # output on an attacker-chosen point (worst case a valid signature read as + # invalid), not key or secret disclosure. The other copy (5.0.0 via + # libp2p-identity) is fixed in Cargo.lock by the 5.1.0 bump, so this ignore + # applies to 4.1.3 only. REMOVE when Cargo.lock has no curve25519-dalek + # below 5.1.0: `grep -A1 'name = "curve25519-dalek"' Cargo.lock`. + # Retirement owner: node maintainers, enforced by the weekly audit-schedule + # drift guard ("Fail if curve25519-dalek moved while its ignore remains"). + "RUSTSEC-2026-0620", # curve25519-dalek AVX-512 bug (4.1.3 needs nightly; no 4.x fix) ] diff --git a/.github/workflows/audit-schedule.yml b/.github/workflows/audit-schedule.yml index 7174888b7..fc35f654b 100644 --- a/.github/workflows/audit-schedule.yml +++ b/.github/workflows/audit-schedule.yml @@ -110,3 +110,24 @@ jobs: exit 1 fi echo "No drift: lru ignore is consistent with the pinned versions." + + # Drift guard: the RUSTSEC-2026-0620 (curve25519-dalek) ignore is only + # valid while the lockfile holds exactly the versions it was written for + # (4.1.3 via ed25519-dalek 2 and crypto_box, 5.1.0 via libp2p-identity). + # Any move, whether the 4.x copy leaving the tree or a vulnerable 5.0.0 + # returning, must revisit the ignore. Retirement owner: node maintainers, + # via this weekly job (see the waiver comment in .cargo/audit.toml). + - name: Fail if curve25519-dalek moved while its ignore remains + run: | + set -euo pipefail + versions="$(grep -A1 'name = "curve25519-dalek"' Cargo.lock | grep '^version' | cut -d'"' -f2 | sort -u | tr '\n' ' ')" + echo "curve25519-dalek versions in Cargo.lock: ${versions:-not present}" + dalek_ignore_present=false + if grep -q 'RUSTSEC-2026-0620' .cargo/audit.toml; then + dalek_ignore_present=true + fi + if [ "$dalek_ignore_present" = true ] && [ "${versions}" != "4.1.3 5.1.0 " ]; then + echo "::error::curve25519-dalek versions are [${versions:-absent from Cargo.lock}] but the RUSTSEC-2026-0620 ignore is still in .cargo/audit.toml. Re-triage the waiver against the advisory's patched range (>=5.1.0) and either drop the ignore or update the pinned set." + exit 1 + fi + echo "No drift: curve25519-dalek ignore is consistent with the pinned versions." From 341283ae1cece081aceeb3bcab4a3580bbc3f4b9 Mon Sep 17 00:00:00 2001 From: beardthelion <56458543+beardthelion@users.noreply.github.com> Date: Mon, 30 Nov 2026 11:20:34 -0600 Subject: [PATCH 5/5] ci(audit): let the dalek drift guard pass once the waiver is retired The curve25519-dalek guard exited on grep's status when the package left the lockfile, and treated the advisory id in an explanatory comment as an active ignore. Tolerate an absent package and match only the quoted ignore entry, so deleting the waiver ends the check cleanly while a retained waiver against a moved version set still fails. --- .github/workflows/audit-schedule.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/audit-schedule.yml b/.github/workflows/audit-schedule.yml index fc35f654b..dde7899c3 100644 --- a/.github/workflows/audit-schedule.yml +++ b/.github/workflows/audit-schedule.yml @@ -120,10 +120,10 @@ jobs: - name: Fail if curve25519-dalek moved while its ignore remains run: | set -euo pipefail - versions="$(grep -A1 'name = "curve25519-dalek"' Cargo.lock | grep '^version' | cut -d'"' -f2 | sort -u | tr '\n' ' ')" + versions="$(grep -A1 'name = "curve25519-dalek"' Cargo.lock | grep '^version' | cut -d'"' -f2 | sort -u | tr '\n' ' ' || true)" echo "curve25519-dalek versions in Cargo.lock: ${versions:-not present}" dalek_ignore_present=false - if grep -q 'RUSTSEC-2026-0620' .cargo/audit.toml; then + if grep -qE '^[[:space:]]*"RUSTSEC-2026-0620"' .cargo/audit.toml; then dalek_ignore_present=true fi if [ "$dalek_ignore_present" = true ] && [ "${versions}" != "4.1.3 5.1.0 " ]; then