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..dde7899c3 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' ' ' || true)" + echo "curve25519-dalek versions in Cargo.lock: ${versions:-not present}" + dalek_ignore_present=false + 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 + 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." 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", 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( 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