fix(indexer): bucket rate-limit key by IPv6 /64 (#282) #776
No reviewers
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic!776
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "qa/282-ratelimit-ipv6-bucket"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implemented per your call ("we do not have a CG-Connecting-IP or X-Forwarded-For ... proceed with the implementation for rate limiting IP addresses").
Since there's no trusted forwarded header, I kept the key on the socket peer IP (a forwarded-header extractor would only add a spoofable bucket key on a wrong trust boundary). The remaining gap was the default PeerIpKeyExtractor keying on the FULL IPv6 address — a client can rotate through its own /64 (the smallest block a host gets) to multiply its limit. So I added a custom KeyExtractor that collapses IPv6 to its /64 prefix; IPv4 keeps the full address. It goes through the single apply_rate_limit_layer chokepoint, so both the general limiter and the lcd-heavy one (#278) get it.
Tests: rate_limit_key_tests — two addresses in the same /64 share one key, different /64s and IPv4 stay independent, and the extractor reads ConnectInfo and buckets by /64. The existing burst->429 integration tests (lcd_heavy_route_rate_limit_returns_429, cg_cmc_orderbook_lcd_heavy_rate_limit_returns_429, rate_limit_returns_429_when_exceeded) stay green.
If you later put it behind a proxy that DOES inject a trusted client-IP header, that's a one-line extractor swap — flag me and I'll wire SmartIp with the trusted hop.
mentioned in issue #282
Security review
Commit reviewed:
5b236b2a4d0273ba34749d3b2ae3bf88832cb6ccScope:
indexer/src/api/mod.rs— customPeerIpV6Slash64KeyExtractor+rate_limit_ip_key()wired intoapply_rate_limit_layer(covers global and LCD-heavy governors).Outcome:
FINDINGS: 0medium+Summary
This MR closes the IPv6 /64 rotation bypass described in #282 for a directly exposed deployment (peer-IP keying, no spoofable forwarded-header extractor). The extractor reads
ConnectInfo<SocketAddr>from the TCP accept path (not client-controlled HTTP headers), andGovernorError::UnableToExtractKeyfails closed with HTTP 500 per tower_governor defaults — not a bypass.Checked attack paths (no medium+ issues):
serve()always usesinto_make_service_with_connect_info.::ffff:…) on dual-stack bind: Would collapse all mapped v4 peers to::(shared bucket). DefaultAPI_BIND=127.0.0.1is IPv4-only in this repo; not treated as a confirmed prod exposure without evidence of::bind.Existing integration tests (
security.rs429 burst cases) and new unit tests (rate_limit_key_tests) provide adequate coverage for the changed keying logic.Inline threads: none (no medium+ findings).
mentioned in commit
e70f2f9e75mentioned in merge request !779