Skip to content

fix(access): require a tailnet source for Tailscale login headers - #1062

Merged
devswha merged 2 commits into
mainfrom
fix/tailscale-login-only-from-serve
Oct 14, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/tailscale-login-only-from-serve

Conversation

@devswha

@devswha devswha commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

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-152 on main) gave full owner access to any loopback request whose Tailscale-User-Login header matched the PC's owner login. server/index.ts:1687 read 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 reads X-Forwarded-For into the request shape.
  • server/access.ts: the login header counts only when the request carries exactly one X-Forwarded-For address inside 100.64.0.0/10 or fd7a:115c:a1e0::/48. A missing value, a proxy chain, a non-tailnet address, malformed input or an IPv4-mapped spelling refuses with pairing_required.
  • A login header that is rejected is still a login header. It does not fall through to the serve-only "no login, one tailnet owner" grant (isServeOwnerRequest), because that grant still requires tailscaleLogin === null. Requests with no header keep today's serve-only behavior.
  • Unchanged: the token and paired-device paths and their precedence, error envelopes, and the wire protocol.

Why this matches what tailscale serve sends (Tailscale v1.102.3):

  • ipn/ipnlocal/serve.go#L1068-L1106: addProxyForwardedHeaders sets X-Forwarded-For to the single source address (c.SrcAddr.Addr().String()). addTailscaleIdentityHeaders deletes any incoming identity headers and sets the login only when that serve context exists.
  • net/tsaddr/tsaddr.go#L30-L35 (CGNATRange, 100.64.0.0/10) and #L87-L90 (TailscaleULARange, fd7a:115c:a1e0::/48).

Serve always sends one tailnet X-Forwarded-For alongside 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

  • Regression tests (fail on main, pass here): server/access.test.ts gets 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's access.ts and index.ts, all 10 fail (20 pass / 10 fail); on this branch, 30 pass / 0 fail.
  • Controls: single tailnet IPv4 addresses (including both range ends) and IPv6 addresses in either case are accepted.
  • Contract: server/api.contract.test.ts adds a regression that drives the real server with the four rejected shapes (401 unauthorized, health reason pairing_required) plus an IPv6 control. It also adds a serve-only case where a rejected login is refused at this PC's Host.
  • Live HTTP, real curl -i against createServer on port 0 with an owner login and an isolated state dir:
    • Before (main): Tailscale-User-Login: owner@x with no XFF, 127.0.0.1, 203.0.113.50, or two XFF values each returned 200 {"devices":[]}.
    • After: each of those returns 401 {"error":{"code":"unauthorized",...}}.
    • After: a single XFF of 100.101.102.103 or fd7a:115c:a1e0::1 returns 200, and a plain local request with no proxy headers returns 200.
  • A real tailscale serve round 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: pass
  • HERDR_TEST_MODE=unit bun test ./server/access.test.ts: 30 pass, 0 fail
  • bun 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 fail
  • HERDR_TEST_MODE=unit bun test ./scripts/changelog-fold.test.ts: 12 pass
  • bun run check fast: pass (run by the implementer)

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

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c482c6ee-03d1-4e6a-958f-634dd1035a27
📥 Commits

Reviewing files that changed from the base of the PR and between 0de23fc and 022e37c.

📒 Files selected for processing: 6
  • changelog.d/tailscale-forwarded-login.md
  • server/AGENTS.md
  • server/access.test.ts
  • server/access.ts
  • server/api.contract.test.ts
  • server/index.ts
  • 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

Comment @coderabbitai help to get the list of available commands.

@devswha
devswha merged commit 79562d1 into main Oct 14, 2026
17 checks passed
@devswha
devswha deleted the fix/tailscale-login-only-from-serve branch October 14, 2026 10:52
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.

1 participant