Repository navigation
fix(serve): bound filtered walks, pre-auth trickles and empty pack chunks - #361
Merged
Merged
Conversation
walk_tree_sized deduped expansion by (tree id, path) under a filter. A chain of N trees whose two entries name the same child is a few KB with 2^N distinct paths, so one PutObject chain made every filtered GetPack (a blob:limit clone or fetch, scope = every path) read 2^N trees. A verdict depends on the path only while a directory is a strict ancestor of a filter prefix. Once a directory matches the scope, every descendant does too, so its expansion key drops the path and it is read once by id. Path-bound keys remain only for prefix ancestors and roots. Test: on the unfixed walk a 20-level chain read 2097152 objects (9 s); the 18-level test now asserts under 2 * levels + 8 reads.
The 30 s opening timeout was a per-read socket timeout, so a peer sending one byte every 29 s held a connection slot for about 66 h before any token check, and 32 of them filled the default --max-connections. The TLS handshake ran under the same per-read bound. The deadline is now fixed at accept and every socket read narrows SO_RCVTIMEO to what is left, failing as timed out at zero. For TLS the narrowing happens in the socket under rustls (server_stream takes the deadline), since rustls reads a record in as many socket reads as the peer splits it into. The session timeout replaces the deadline after the 200 status.
write_pack_stream never frames zero bytes, but read_pack_stream accepted empty chunks without limit. An empty chunk advances neither the --max-pack-size count nor the idle timeout, so a peer could hold a session on it for ever. It is now a protocol error.
rustls also writes during the handshake (the certificate chain), so a peer that completes ClientHello and then stops reading could hold the slot past the deadline. DeadlineTcp now narrows SO_SNDTIMEO to the time left before each write, like reads. set_socket_timeouts already replaces the deadline and sets both session timeouts at handoff; a test pins that the narrowed write timeout does not survive it.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
tonibergholm
approved these changes
Nov 20, 2026
tonibergholm
left a comment
Member
There was a problem hiding this comment.
Reviewed: sol-loop (3 rounds), required checks green, Codex review has no findings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A security audit found three ways a peer could tie up
sc servecheaply.GetPackdeduplicated trees by (id, path). A chain of trees whose two entries name the same child is a few KB but has2^depthpaths. On the unfixed code a 20-level chain made the walk read 2,097,152 objects. Any writer can plant such a chain withPutObject, and any reader can then trigger the walk. Now a directory wholly inside the filter scope is keyed by id alone, so each tree is read once. Only the ancestors of a filter prefix keep their path in the key.--max-connections. Now one 30 s deadline fixed at accept covers the handshake and the opening, for reads and writes, and the session timeouts replace it after the 200. On macOS an operator-supplied--tls-certchain larger than the send buffer can still outlast the deadline; this is documented in the threat model.ST_PACK_CHUNKframes never advanced the size cap or the idle timeout. An empty chunk is now a protocol error; no sender emits one.Proof: each fix has a test that failed or hung on the unfixed code:
filtered_walk_over_a_diamond_chain_is_linear(2M reads before, bounded reads after).a_trickled_opening_fails_at_the_overall_deadlineanda_trickled_handshake_fails_at_the_overall_deadline(killed after 25 s before, about 0.7 s after).a_write_to_a_peer_that_never_reads_fails_at_the_deadline.read_pack_stream_refuses_an_empty_chunk.cargo test -p scl-tlsioand thescl-repolib suite pass locally. One bucket compaction contention test failed once under load and passed when rerun; it does not touch these paths.Reviewed with sol-loop: 3 rounds with gpt-6.2-sol. Sol verdict: changes requested on one item, declined. It concerns the macOS send-timeout behaviour with operator cert chains over about 128 KiB, which is documented as a known limit instead of being fixed with nonblocking I/O.
Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.