Repository navigation
Conversation
HugoXK-bot
requested changes
Nov 16, 2026
HugoXK-bot
left a comment
Collaborator
There was a problem hiding this comment.
Verdict: CHANGES at 0d4f785
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
src/lib/rateLimit.ts:31-32returnsmapped[1]!before theisIPguard at:33, so an unparseable mapped spelling still mints its own key: at this tiprateLimitKey({ip:'::ffff:1.2.3.999'})is1.2.3.999,::ffff:1.2.3.998is1.2.3.998,::ffff:256.0.0.1is256.0.0.1,::ffff:001.2.3.4is001.2.3.4- none of them isOPAQUE_ADDRESS_KEY(:11). Take that branch only whenisIP(mapped[1]!) === 4, otherwise fall through to theversion === 0case at:35.- It is reachable, measured at this tip: with
trustProxy: ['10.0.0.1'], 40POST /auth/tokenwhoseX-Forwarded-Forwas::ffff:1.2.3.999down to.960all answered 400 and never 429, while 40 invalid nine-group values (1:2:3:4:5:6:7:8:0up to:39) turned 429 from request 31 - so the limiter is active and each malformed mapped spelling took a fresh bucket.@fastify/proxy-addr@5.1.2(index.js:262) rejects such a candidate and truncates the hop list to it, which makes itrequest.ip. - That contradicts the issue's binding security acceptance ("an address that cannot be parsed must map to the same single opaque bucket every time") and this PR's own bullet;
test/rateLimit.test.ts:43-58adds only the nine-group andnot-an-addressspellings, so the suite stays green with the hole open. - The config half is sound at this head: covering IPv4 and IPv6 pairs, the three-entry sets,
::ffff:0:0/96in both spellings and the mapped/97pair are refused with the covering entries named (src/config.ts:286-289, message at:403-406); host bits are masked (0.0.0.1/1,128.0.0.1/1refused);0.0.0.0/1,128.0.0.0/2,10.1.2.3/8,127.0.0.1,::1,172.17.0.0/16,::ffff:0:0/95stay accepted, andloadConfigreaches the check (:421). - Non-blocking: the body's coverage provenance
--head 4e18e910...does not resolve in this repository (422), so that reading cannot be re-run here.
Ran:
curl https://api.github.com/repos/HugoXK/fledge/pulls/910- head0d4f7857..., base8213cec5..., 5 files+210 -5, 0 reviewsnpm run checkon this tree - exit 0, 2453/2453 (lint, typecheck, tests, build)npx tsx --test test/rateLimit.test.ts- 16/16node scripts/changelog.mjs check- 29 fragments ok;node scripts/version.mjs check-0.4.0 ok- scratch probe in this tree (deleted afterwards): the four
rateLimitKeyreadings above, 40 mapped-invalid vs 40 nine-group-invalid/auth/tokenrequests through a trusted hop, 24parseTrustProxysets (13 refused, 11 accepted) git status --porcelainafter the probe - clean, tree still equals the tip
Not run: a live install or a production boot with a covering TRUST_PROXY; Docker; risk-gate locally (its check-run on this head is green).
Owner
Author
|
Written-by: HugoXK @HugoXK-bot open PR queue, oldest first:
Please take them in that order and name the blocking sentence when you request changes. |
This was referenced Nov 16, 2026
…resses one bucket (#171)
HugoXK
force-pushed
the
dev4/171-rate-limit
branch
from
November 16, 2026 08:27
0d4f785 to
8b28667
Compare
This branch has not been deployed
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.
Written-by: Fledge Platform Dev-4
Author: Fledge Platform Dev-4
Fixes #171
A trusted hop forwards the client header verbatim, so
request.ipcan be a value that is not an address at all. Two things went wrong with that:ipv6GroupsbuiltArray(8 - groups)and threwRangeError: Invalid array lengthfor a nine-group value, andparseTrustProxychecked each hop but never their union, so0.0.0.0/1,128.0.0.0/1was accepted and trusted every caller.rateLimitKeyasksnode:net'sisIPfirst. IPv4 stays exact, a valid IPv6 address still keeps its/64, and anything that is not an address returns one constant key (OPAQUE_ADDRESS_KEY) rather than a key derived from the malformed text: a distinct key per spelling would be an oracle that mints a bucket per request. The group count is floored too, so the array can never be built with a negative length.parseTrustProxycombines the entries. Host bits are masked, IPv6 is compared with BigInt, and an IPv4-mapped entry is folded into the IPv4 space at prefix length − 96, because@fastify/proxy-addr@5.1.2canonicalises a mapped candidate to IPv4 and then matches a mapped subnet of/96or longer against it. A list whose union is the whole IPv4 or IPv6 space is refused with a message that names the entries that cover it, in the shape of the existing refusal atsrc/config.ts:283. A mapped entry below/96matches no candidate in the library and is not counted as IPv6 coverage.loadConfigcallsparseTrustProxy, so an operator meets it at boot, and the security fragment says the service will not start until the env is fixed.docs/deploy.mdstates the union rule beside the paragraph that already names the refused spellings and/0.Direction: the card's pinned decision, refuse a covering prefix set at startup, not "accept and document".
Re-cut by the Lead onto
8213cec5035f7abb9764c9449ecf074a7f1a9cdd(the main#906produced). Four of the five files are the reviewed tree unchanged; onlydocs/deploy.mdmoved on main (1b8686ec→fefa7bc1, from#894/#902/#906), so that one file is a three-way merge. Verified per file at this head:src/config.tsc739badf,src/lib/rateLimit.ts12429530,test/rateLimit.test.tse65f2524,docs/deploy.md66f4cd74, the fragmentd1c49723.Second head on this branch after the verdict's blocking finding (
5916611573): the mapped::ffff:branch ran before theisIPguard, so::ffff:1.2.3.999,::ffff:1.2.3.998,::ffff:256.0.0.1and::ffff:001.2.3.4each minted a key of their own. The fold is now decided by validity —isIP(mapped[1]) === 4keeps the IPv4 address, anything else returnsOPAQUE_ADDRESS_KEY— andtest/rateLimit.test.tspins the four spellings plus a request-level case where 31 malformed mapped values all land in one bucket (the 31st answers 429, not a fresh bucket).src/config.tsis untouched by this fix: the verdict found the covering-set half sound.Probe at this head:
::ffff:1.2.3.999/.998/256.0.0.1/001.2.3.4→unparseable-address;::ffff:1.2.3.4→1.2.3.4;1:2:3:4:5:6:7:8:9→unparseable-address;2001:db8:1:2::1→2001:db8:1:2::/64.Ran:
npm run check— exit 0, 2454/2454 (lint, typecheck, tests, build), run on this exact tree (9251ae12, head8b28667f, cut on8213cec5)npx tsx --test test/rateLimit.test.ts— 16/1678ea77a3— 13/16, the three new behaviour cases red (RangeError: Invalid array lengthon the helper; a forwarded nine-group value answering 500 at the HTTP boundary;0.0.0.0/1,128.0.0.0/1accepted instead of refused)npm run test:coverageandnode scripts/coverage-diff.mjs --base 78ea77a3d74a1813871b11ff1a69d0c6c8cc5b66 --head 4e18e9104cd6d1ed76c2742c59a87ed3c47f2483 --report <coverage log> --floor 80— ok, 89/89 changed lines (100%, floor 80)node scripts/risk-gate.mjs --base 8213cec5035f7abb9764c9449ecf074a7f1a9cdd—risk-tier: T3; basis: src/config.tsnode scripts/changelog.mjs check— 29 fragment(s) ok;node scripts/version.mjs check— 0.4.0 okNot run: a live install with GitHub; a real production boot with a covering env (the refusal is exercised through
loadConfigin tests); Docker.Risk:
src/config.tsandsrc/lib/rateLimit.tsare T3. The refusal only narrows what an operator may configure (a covering set now fails at boot instead of silently trusting everyone), and the constant key only merges malformed values into one bucket.Docs:
docs/deploy.mdcarries the union rule and the unparseable-address bucket;changelog.d/171-trust-proxy-coverage.security.mdis the fragment.Tree
9251ae12b3cb31bc4e2dc825ff226aa96aa4add9, head8b28667f95ea27c7641339728f497ee32dee13d4, parent8213cec5035f7abb9764c9449ecf074a7f1a9cdd: 5 files, +233 −6.