refactor(rate-limit): parse client IPs with node:net #341
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
priority
high
priority
low
priority
medium
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-web!341
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "refactor/ip-parse-node-net"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
What
Replace the hand-rolled IPv4/IPv6 parser in
src/lib/rate-limit.tswithnode:netisIPv4/isIPv6and URL-based normalisation. About 110 lines of parsing go. The file's comment essays shrink to one-line whys. Patch bump to 1.29.2.ipBucketkeeps its contract: IPv6 keys as its /56, IPv4 exactly,::ffff:a.b.c.das the IPv4 address, unparseable input as-is.Behaviour
Compared old and new
ipBucketon 200,000 random strings built from address fragments, plus a fixed list of edge cases. Output is identical for every input Node accepts as an IP (brackets, zone ids, compressed forms, mapped forms, dotted tails).The two parsers differ only on malformed input the old code accepted by mistake. Those now pass through unchanged, like any other unparseable value:
010.0.0.1, which is ambiguous octal).1.2.3.4::).Tests
Existing
ipBuckettests are unchanged. Added cases:::ffff:cb00:7109, uppercase long form, bracketed, with zone id,::ffff:0:0);pnpm check,pnpm lint,pnpm testandpnpm buildpass.Comments
The long header and budget comments (sizing rationale for the sign-up and resend budgets, the shared-egress decision) are cut to one-line whys, per the comment rule. The full text stays in git history of this file and issue #142.
db5af7d23a67d3410f9367d3410f936740c5c039