Repository navigation
Conversation
Authentication bans and connection limits keyed on the TCP peer, so behind a reverse proxy every client shared the proxy's address. One client failing auth jailed the proxy for 15 minutes and NodeLink reset all of its connections, which the proxy surfaced as HTTP 502. Enabling trustProxy did not help: the socket guards ignored it, and when enabled it trusted forwarding headers from any peer, so identities were spoofable. - Resolve the client address only through admission.trustedProxies (IPs/CIDRs), walking X-Forwarded-For from the nearest hop and ignoring forwarded identities from untrusted peers - Apply auth bans and REST/WebSocket upgrade limits per client - Give trusted proxies a separate aggregate TCP pool (admission.ip.maxProxySockets) and release capacity on close - Treat loopback requests carrying forwarding headers as external in the profiler and workers endpoints
PWSL calls removeAllListeners() on the TCP socket right after ending or destroying it, so 'close' listeners never ran for upgraded sockets. Every closed WebSocket kept its per-IP slot, and with this branch also its per-client and trusted proxy slots, until clients were refused. - Track releases per socket and run them once, from the WebSocket 'close' event, its destroy() (protocol errors and server teardown emit no 'close') and TCP 'close' as a fallback - Reserve peer and per-client capacity for Bun upgrades, which have no TCP connection hook, and release it on failed upgrade or close
|
All Contributors have signed the CLA. The PR is now allowed to be merged. |
Author
|
I have read the CLA Document and I hereby sign the CLA |
performanc-bot
added a commit
to PerformanC/CLA-Signatures
that referenced
this pull request
Oct 10, 2026
- Match trusted proxies with net.BlockList instead of a hand-rolled CIDR parser, keeping IPv4 and IPv6 rules in separate lists so an address only matches rules of its own family - Keep releaseSocket private to socketRelease.ts - Drive the auth isolation tests through the real REST handler and WebSocket upgrade instead of feeding admission the client IP - Drop the duplicated aggregate pool unit test and the unused session handlers from the transport harness, and destroy upgraded sockets on teardown so a failing test cannot hang - Add a Bun-only regression for upgrade capacity (bun test)
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.
Changes
Fixes #247.
X-Forwarded-Forwhen the TCP peer is inadmission.trustedProxies(IPs or CIDRs). XFF is walked right to left skipping trusted hops,X-Real-IPis only used when there's no XFF. Untrusted peers always get their socket address.admission.ip.maxProxySockets, default 1024) instead of the per-IP 25, and per-client limits are applied at the upgrade.removeAllListeners()on the TCP socket right after ending/destroying it, so theclosehandler inhttpServer.tsnever ran for upgraded sockets. That one was already there before this PR: every closed WS kept its per-IP slot, so a bot that reconnects a lot ends up locked out after ~25 reconnects until restart.Why
Behind nginx/caddy/whatever, one client failing auth 5 times jails the proxy IP for 15 min and every other client starts getting 502s. Details and repro in #247.
Checkmarks
Additional information
To enable it:
or
NODELINK_ADMISSION_TRUSTPROXY=true+NODELINK_ADMISSION_TRUSTEDPROXIES=127.0.0.1,10.0.0.0/8.Behavior change:
trustProxy: truewith an empty list used to trust headers from anyone, now it ignores them and logs a warning on startup.Tested:
node --test src/utils/clientAddress.test.ts src/server/clientIsolation.test.tsclientAddress: XFF walking, trusted proxy matching (usesnet.BlockList, IPv4/IPv6 rules kept separate), loopback checkclientIsolation: spins up the real http server + PWSL. Auth failures are sent through REST and the WS upgrade (only the bad client gets banned), and socket slots come back after client close / server destroy. All of these fail on the old codebun test src/server/bunServer.test.ts(Bun only, node skips it): same limits and release through the realBun.serve. Fails without the Bun changesdistis recompiled in theupdate:commits, only the files that actually changed.