Repository navigation
Conversation
Every failed POST /v1/pairing/join now counts against the client and a relay-wide budget. The attempt is reserved before the code lookup and refunded only if the join succeeds. Once either budget is spent, every join is refused with 429 too_many_attempts, including one with the correct code, so the response never reveals whether a code exists. - Per client: 10 failures per 15 minutes, IPv6 grouped by /64. - Relay-wide: 20 failures per pairing TTL (120 s). A code's lifetime overlaps at most two windows, so at most 40 of the 10^6 codes can be tested while a session is open (<= 4e-5). Compile-time assertions keep this bound in sync with the constants. - Opt-in CLIPSYNC_RELAY_TRUSTED_PROXIES / --trusted-proxies: X-Forwarded-For is read only from these peers, using the rightmost untrusted hop. Unset means the TCP peer address only, as before. - gc() expires ip_fails entries. Refused attempts allocate no entries. - The client maps 429 to an actionable message.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
| )); | ||
| } | ||
| assert!(matches!( | ||
| state.join_pairing(join(&wrong_code(&offer, 0), DeviceId::new()), attacker), |
| let fresh: IpAddr = "192.0.2.200".parse().unwrap(); | ||
| // Unknown and correct codes are refused identically once the budget is spent. | ||
| assert!(matches!( | ||
| state.join_pairing(join(&wrong_code(&offer, 0), DeviceId::new()), fresh), |
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.
Problem
POST /v1/pairing/joinnever counted a failed join. Unknown codes returned 404 without being recorded.RelayState::record_ip_failexisted but nothing called it, so the per-IP limit incheck_ipcould never trigger. The per-sessionattemptscounter only increments after a code has already matched, so it does not limit guessing.Attack scenario
One client can submit wrong 6-digit codes as fast as the relay answers and never be throttled. At loopback speed that covers a large share of the 10^6 code space within one 120 s pairing TTL. The code is also the SPAKE2 password, so an attacker who hits it can complete pairing and join the victim's room. Before this change, a sweep of 20,000 wrong codes from one address got only 404s and no 429s, and the correct code still joined afterwards.
Resulting behavior
constassertion fails the build if the constants stop satisfying this bound.429 too_many_attemptsbody, including one with the correct code. Refused attempts are not counted and allocate no state.CLIPSYNC_RELAY_TRUSTED_PROXIES/--trusted-proxiestakes a comma-separated list of addresses and CIDRs.X-Forwarded-Foris read only when the TCP peer is in that list, and the relay uses the rightmost hop that is not itself trusted. A malformed hop falls back to the nearest trusted proxy. Default: the TCP peer address only, unchanged from before.gc()removesip_failsentries whose window has ended.Compatibility
There are no protocol, wire or persisted-format changes. The 429
too_many_attemptscode and body already existed. Code length and format are unchanged.router(config)andRelayState::new(config)keep their signatures and behavior;router_with_trusted_proxies/RelayState::with_trusted_proxiesare additive.record_ip_failis now test-only because nothing in production called it.Verification
X-Forwarded-Forhonored only from configured proxies, with forged leftmost entries ignored. This test was checked by mutation: honoring the header from any peer makes it fail.cargo +1.100.0 fmt --all -- --check: passcargo +1.100.0 clippy --workspace --all-targets --locked -- -D warnings: passcargo +1.100.0 test -p clipsync-relay --locked: 86 passed, 0 failedcargo +1.100.0 test -p clipsync-core --locked: 58 passed, 0 failedcargo +1.100.0 test --workspace --locked --no-fail-fast: 338 passed, 0 failed (46 test binaries)secure_listener::tls12_and_tls13_verify_issuer_hostname_and_reject_plaintexthit a TLS-handshakeConnectionResetunder parallel load. It passed in 5 of 5 isolated reruns and in the full rerun, and that test does not depend on the join limits.cargo +1.95.0 check --workspace --all-targets --locked: passRemaining limitations
docs/self-hosting.mddocuments this.docs/regressions.json/docs/regression-audit.md.