fix: prevent localhost auth bypass via X-Forwarded-For spoofing#38
Closed
marcusquinn wants to merge 3 commits intojohnwaldo:mainfrom
Closed
fix: prevent localhost auth bypass via X-Forwarded-For spoofing#38marcusquinn wants to merge 3 commits intojohnwaldo:mainfrom
marcusquinn wants to merge 3 commits intojohnwaldo:mainfrom
Conversation
Add TRUST_PROXY config flag (default false). When false, use Bun's native requestIP() for client IP detection instead of trusting spoofable proxy headers. Consolidate IP extraction into auth.ts as single source of truth. Closes johnwaldo#19
Owner
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.
Summary
Fixes #19 — Security: Localhost auth bypass via X-Forwarded-For spoofing
TRUST_PROXYconfig flag (defaultfalse). When false, the server uses Bun's nativerequestIP()to read the TCP socket address for client IP detection — this cannot be spoofed by clients sending fakeX-Forwarded-FororX-Real-IPheadersTRUST_PROXY=true(for deployments behind Tailscale Serve, Traefik, nginx), proxy headers are trusted as beforeserver/index.tsintoserver/middleware/auth.tsasextractClientIp()— single source of truthChanges
server/config.tstrustProxyconfig (env:TRUST_PROXY, defaultfalse)server/middleware/auth.tsextractIp()withextractClientIp()that respectstrustProxy; export for use byindex.tsserver/index.tsextractRemoteIp(); importextractClientIpfrom auth; addtrustProxyto startup logREADME.mdTRUST_PROXYflag, deployment matrix, Tailscale Serve header strippingSecurity Impact
Before: Any remote client could send
X-Forwarded-For: 127.0.0.1and bypass authentication entirely.After: By default, proxy headers are ignored. The TCP socket address (from
requestIP()) determines the client IP. Only whenTRUST_PROXY=trueare forwarded headers consulted.Testing
trust proxy: falsein startup logX-Forwarded-Forheaders ignored whenTRUST_PROXY=false