Registry Mirror
Skip to content

Conversation

@Totopo27

Copy link
Copy Markdown
Contributor

Summary

 const fetch = (req: Request): Promise<Response> => {
-  if (SERVE_HEADERS.some((name) => req.headers.has(name))) {
+  const hasTailscaleHeader = SERVE_IDENTITY_HEADERS.some((name) => req.headers.has(name));
+  const forwardedFor = req.headers.get("x-forwarded-for");
+  const hasExternalForwardedFor = forwardedFor !== null && !isLoopbackForwardedFor(forwardedFor);
+
+  if (hasTailscaleHeader || hasExternalForwardedFor) {
     tailscale.noteServedRequest();
     return Promise.resolve(localOnly());
   }

Local reverse proxies (e.g. nginx, Caddy, inbox.localhost via portless) add an X-Forwarded-For header with loopback addresses (127.0.0.1, ::1, etc.). The inbox previously treated any request carrying X-Forwarded-For as tailnet exposure and returned 403 local_only.

This fix checks X-Forwarded-For with isLoopbackForwardedFor:

  • Requests carrying tailscale-headers-info or tailscale-user-login are still blocked as tailnet exposure.
  • Requests carrying x-forwarded-for are only blocked if they contain a non-loopback IP/host (which is what Tailscale serve forwards when proxying remote/tailnet peers).
  • Local reverse proxies forwarding loopback IPs pass through cleanly.

Fixes #1867.

Evidence

  • Unit tests:
    • Added test coverage in packages/shared/loopback-host.test.ts for isLoopbackForwardedFor.
    • Added regression test in packages/server/inbox-tailscale.test.ts verifying that loopback X-Forwarded-For values return 200 while non-loopback IPs return 403.
bun test packages/shared/loopback-host.test.ts
3 pass, 0 fail, 33 expect() calls

bun test packages/server/inbox-tailscale.test.ts -t "a hand-made mapping onto the window"
1 pass, 21 filtered out, 0 fail, 24 expect() calls

Merge Danger

Door: two-way (standard low-risk refactor of loopback proxy detection).
Blast Radius: narrow (only affects loopback port fetch handler in Inbox server when x-forwarded-for is present).

@backnotprop
backnotprop merged commit d2dce76 into backnotprop:main Oct 22, 2026
28 checks passed
@Totopo27
Totopo27 deleted the fix/inbox-loopback-forwarded-for branch October 22, 2026 13:12
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.

Inbox refuses all reverse-proxy requests: x-forwarded-for treated as tailnet exposure (breaks local proxies)

2 participants