Repository navigation
Pairing cleanup after #7: Serve-mode warning, replay test, subtle, per-client challenge limit - #8
Merged
Merged
Conversation
- README: only Serve's HTTP-proxy mode satisfies the local-only gate; a raw or TLS-terminated TCP forward, or any proxy without X-Forwarded-For, defeats it. - Test a challenge replay: the second use is refused and no grant or pairing state changes. - Replace the hand-rolled constant-time compare with subtle::ConstantTimeEq; take_token and take_ticket still scan every entry. - Key the challenge rate limit on the proxied client (X-Forwarded-For, then the Tailscale identity headers) instead of one global bucket; the 429 is unchanged. - Bump rustix 1.1.5 to 1.1.6 for RUSTSEC-2026-0486 so cargo deny passes.
The caller writes everything to the left of the hop the proxy appends, so the right-most X-Forwarded-For element is the only trusted one; key on it, trimmed and with any port dropped. Earlier elements no longer mint a new bucket. Fold the Tailscale identity headers to lower case before truncating, so case variants of one identity share a bucket. Tests: a rate-2 caller rotating the leading element of a two-hop header still gets 429, and two case variants of one identity share a bucket. The rotation test fails on the previous keying.
VirtualMachinist
marked this pull request as ready for review
November 14, 2026 05:13
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.
Follow-up to #7 at
72fcdd4. Four items from the security re-review of that head plus one QA gap. Two commits, plus a merge ofmaine092c2f(app Lapis pin bump). No schema change.Rows
C1 — Serve mode warning (README). Adds a sentence next to the existing Serve paragraph: only Serve's HTTP-proxy mode is supported (
tailscale serve --bg --https=8443 http://127.0.0.1:8780); a raw TCP forward, a TLS-terminated TCP forward, or any proxy that does not addX-Forwarded-Fordefeats the local-only gate.C2 — challenge replay test.
a_challenge_replay_is_refused_and_leaves_state_alone: a paired device opens a grant with a challenge, then sends the identical request again. The second use is403 bad_signature, and a signed write on the grant opened by the first use still returns200, so the refusal released no grant and dropped no device.C3 — constant-time compare. The hand-rolled
ct_eqis gone.take_tokenandtake_ticketnow compare withsubtle::ConstantTimeEqand still scan every entry; only the length leaks, as before.subtlewas already inCargo.locktransitively throughp256, so the direct dependency adds no crate.cargo deny check: advisories, bans, licenses and sources all ok.C4 — per-client challenge rate limit (done, not deferred). The rate bucket is keyed per client instead of one global bucket, so a flood from one caller cannot delay another caller's challenge. Key order: the right-most element of
X-Forwarded-For, trimmed, with anyhost:portport dropped. The proxy appends the trusted hop and strips client-supplied forwarding headers first, so everything to the left of that element is caller-written and is now ignored. Next,Tailscale-User-Login/-Name/-Profile/-Id, lower-cased before the 64-character truncation, so case variants of one identity share a bucket. Finallylocalfor a direct caller that sends no forwarding header. 429 and its body are unchanged.Tests, all at a limit of 2:
challenge_rate_is_per_client_not_global— one address on three ports gets200, 200, 429; a second address and an identity each still get200in the same window.challenge_rate_ignores_a_rotated_leading_forwarded_element— a caller that rotates the leading element of a two-hop header is still refused with429. This test fails on the previous left-most keying (200where429is required).challenge_rate_folds_identity_case— two case variants of one identity fill one bucket and the third is429.What a full map does.
recentholds at most 1024 keys, each with at most the rate window's timestamps (32 by default); expired buckets are pruned on every issue. When the map is full, a key that is not already present is refused with the same429until buckets age out of the window, while keys already present keep working. So a caller that can mint distinct keys can keep a new client out for as long as it keeps the map full, but memory stays bounded and no existing bucket is taken from its client. Reaching that state through the proxy needs distinct trusted identities; a direct loopback caller is the host operator. A request carrying only a bareForwardedheader, with noX-Forwarded-Forand no identity, keys aslocal, so all such callers share one bucket and are refused together rather than bypassing the limit.C4 stayed small (about 75 implementation lines, no new crate), so it is in this PR.
Also in this diff
rustix1.1.5 → 1.1.6 inCargo.lock. A newly published advisory (RUSTSEC-2026-0486, unsound xattr buffer handling) fails thecargo-denyjob on the base lock. The crate arrives throughtempfileas a dev-dependency; no runtime path changes.Verification
Run on the build host, workspace at this head:
cargo check --workspace --all-targets— ok.cargo test --workspace— ok (39 bridge tests, including the four pairing-rate and replay tests;cargo test -p pendant-bridgealso run alone).X-Forwarded-Forelement in a scratch copy makeschallenge_rate_ignores_a_rotated_leading_forwarded_elementfail (200where429is required), so the test pins the new keying.cargo deny check— advisories ok, bans ok, licenses ok, sources ok.rustfmt --edition 2021 --checkon both touched source files — clean.maine092c2f:cargo check --workspace --all-targetsandcargo test --workspaceok;cargo check --manifest-path app/Cargo.toml --all-targets --lockedandcargo test --manifest-path app/Cargo.toml --lockedok (12 passed, 1 ignored, 3 doctests);cargo deny checkandcargo deny --manifest-path app/Cargo.toml checkboth ok.app/matchesmain; the merge added only that pin bump.Follow-up proposal: defence in depth for the local-only gate
The gate reads the presence of a forwarding header, which is correct for the documented Serve mode and is defeated by any other proxy (now warned about in the README). Two options, either of which removes reliance on the header:
GET /v1/pair/qr, the signed revoke and the host revoke. Serve would inject it as a header through a proxy rule; the bridge compares it constant-time. Cost: one config knob and a Serve rule; no wire change for the phone that fetchespair/qrbecause Serve adds it.127.0.0.1:8780as the proxied endpoint and require a token for it, or move the pairing routes to a second loopback port that Serve never forwards to, so only a local process can reach them. Cost: a second listen address in config and a second bind in the accept loop; the PWA gets no phone-facing change.Option 2 is more robust (no header trust at all) and option 1 is smaller. Neither is in this PR; it is a design change and needs your call.
CI on this head
Run
43559838582at146df9b:checkpass,banned-namespass,cargo-denypass. The earlier red step,cargo deny check (app), is cleared by the merge ofmaine092c2f, which moves the app's pinned Lapis rev tov0.5.0(libsqlite3-sys0.40.0) and drops RUSTSEC-2026-0459.Out of scope, untouched
app/src/notes/store.rs,app/src/platform/keystore.rs, port443, the Serve config,serve-apply.sh, the bridge wire schema, andci.yml.