Repository navigation
fix(access): require a tailnet source for Tailscale login headers - #1062
Merged
Merged
Conversation
Keep rejected identity headers out of the serve-only no-login grant while preserving token and paired-device access. Cover IPv4, IPv6, malformed and chained forwarding addresses. Refs #253 Plan: .omo/plans/issue-sweep-2026-10-14.md
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 19 minutes. View limit details
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. Comment |
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.
Refs #253
Partial by design: this filters forwarded-header spoofing from other local proxies; a raw TCP tunnel that forges both headers is still out of reach (see Residual).
Root cause
decideAccess(server/access.ts:149-152on main) gave full owner access to any loopback request whoseTailscale-User-Loginheader matched the PC's owner login.server/index.ts:1687read that header from every request, whichever local process forwarded it. When there is no token, any other reverse proxy on the PC that passes a visitor's own headers through (nginx, Caddy, an HTTP tunnel client) gave the visitor full access for the cost of sending the owner's login.What changed
server/index.ts: also readsX-Forwarded-Forinto the request shape.server/access.ts: the login header counts only when the request carries exactly oneX-Forwarded-Foraddress inside100.64.0.0/10orfd7a:115c:a1e0::/48. A missing value, a proxy chain, a non-tailnet address, malformed input or an IPv4-mapped spelling refuses withpairing_required.isServeOwnerRequest), because that grant still requirestailscaleLogin === null. Requests with no header keep today's serve-only behavior.Why this matches what
tailscale servesends (Tailscale v1.102.3):addProxyForwardedHeaderssetsX-Forwarded-Forto the single source address (c.SrcAddr.Addr().String()).addTailscaleIdentityHeadersdeletes any incoming identity headers and sets the login only when that serve context exists.CGNATRange, 100.64.0.0/10) and #L87-L90 (TailscaleULARange, fd7a:115c:a1e0::/48).Serve always sends one tailnet
X-Forwarded-Foralongside the identity, so the owner's phone through serve still gets in without pairing.Residual: this filters header spoofing through ordinary forwarding proxies. It is not proxy authentication. A raw TCP tunnel that lets the visitor write the whole request can still forge both headers; a token, or a socket only tailscaled can reach, closes that.
Evidence
server/access.test.tsgets 10 new regression cases. Each is a login forwarded for: none,127.0.0.1,203.0.113.50, a two-address chain, just outside both IPv4 ends, the next IPv6 /48, malformed, and IPv4-mapped. The tenth is a rejected login at this PC's Host on a serve-only install. With main'saccess.tsandindex.ts, all 10 fail (20 pass / 10 fail); on this branch, 30 pass / 0 fail.server/api.contract.test.tsadds a regression that drives the real server with the four rejected shapes (401unauthorized, health reasonpairing_required) plus an IPv6 control. It also adds a serve-only case where a rejected login is refused at this PC's Host.curl -iagainstcreateServeron port 0 with an owner login and an isolated state dir:Tailscale-User-Login: owner@xwith no XFF,127.0.0.1,203.0.113.50, or two XFF values each returned200 {"devices":[]}.401 {"error":{"code":"unauthorized",...}}.100.101.102.103orfd7a:115c:a1e0::1returns 200, and a plain local request with no proxy headers returns 200.tailscale serveround trip was not run: this PC's existing Serve/Funnel configuration was not altered. The serve-shaped requests above follow the cited source.Checks run
bun run typecheck: passHERDR_TEST_MODE=unit bun test ./server/access.test.ts: 30 pass, 0 failbun run test:unit: 3530 pass, 0 fail, 8 skip (285 files)HERDR_TEST_SESSION=<own session> bun test ./server/api.contract.test.ts: 120 pass, 0 failHERDR_TEST_MODE=unit bun test ./scripts/changelog-fold.test.ts: 12 passbun run check fast: pass (run by the implementer)