Skip to content

fix(serve): bound filtered walks, pre-auth trickles and empty pack chunks - #361

Merged
tonibergholm-codento merged 7 commits into
mainfrom
fix/serve-dos-bounds
Nov 20, 2026
Merged

tonibergholm-codento merged 7 commits into
mainfrom
fix/serve-dos-bounds

Conversation

@tonibergholm-codento

Copy link
Copy Markdown
Collaborator

A security audit found three ways a peer could tie up sc serve cheaply.

  1. Filtered walks blew up on shared subtrees. A filtered GetPack deduplicated trees by (id, path). A chain of trees whose two entries name the same child is a few KB but has 2^depth paths. On the unfixed code a 20-level chain made the walk read 2,097,152 objects. Any writer can plant such a chain with PutObject, 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.
  2. A slow trickle held connection slots before authentication. The HTTP opening and the TLS handshake had a 30 s timeout per read. A client sending one byte every 29 s therefore held a slot for days before any token check, and 32 such clients filled the default --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-cert chain larger than the send buffer can still outlast the deadline; this is documented in the threat model.
  3. Empty pack chunks looped forever. A stream of empty ST_PACK_CHUNK frames 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_deadline and a_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-tlsio and the scl-repo lib 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.

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.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 914a56ac-3b76-4bed-bba4-6d79c4845231
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T08:29:14.307156Z 46d8a85 PR opened
🔒 Security Review ✅ Completed 2026-11-20T08:31:33.549181Z 46d8a85 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tonibergholm tonibergholm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: sol-loop (3 rounds), required checks green, Codex review has no findings.

@tonibergholm-codento
tonibergholm-codento merged commit 13622ba into main Nov 20, 2026
11 checks passed
@tonibergholm-codento
tonibergholm-codento deleted the fix/serve-dos-bounds branch November 20, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants