IP reputation / dynamic denylist feed
DaloyJS ships ipReputation(). Where ipRestriction() enforces a static allow/deny list compiled once at startup, ipReputation() wires pluggable, periodically-refreshed abuse feeds (Tor exit lists, Spamhaus DROP, cloud-abuse ranges, or your own threat intelligence) into the request path without a redeploy.
- Pluggable feeds: any source that yields IP / CIDR strings.
urlFeed()ships for the common case (fetch a newline / Spamhaus-DROP-style list over HTTP). - Periodic refresh: the denylist reloads on an
unref'd timer so stale ranges expire and new ones are picked up automatically. - Fail-open: a denylist is additive defense, never the only gate. If a feed can't be loaded (initial or refresh), traffic is not blocked: the last-known-good list is retained. A feed outage never takes your app down.
It reuses the same SSRF-grade CIDR matcher as ipRestriction(), is dependency-free, and runs on every supported runtime.
- requestResolve client IPsocket value, or X-Forwarded-For when trustProxyHeaders
- Match the compiled CIDR setsame SSRF-grade matcher as ipRestriction()
- Listed -> blocklog mode never blocks. Only fires onMatch
- Not listed / unresolved IP -> allowfeed outage retains last-known-good. Fail-open
Quick start
The denylist is matched against the rightmost X-Forwarded-For entry (the one your immediate proxy appended), so a listed client cannot dodge it by prepending a clean spoofed entry on the left. Multi-hop chains declare their length with trustedHops (trustProxyHeaders: true is exactly trustedHops: 1). When the origin itself can be reached, set trustedProxies so the peer socket is verified against a CIDR allowlist before any forwarded header is read (see the autoBan note).
Wiring abuse feeds
A feed is anything implementing IpReputationFeed:
urlFeed() covers the common case. It fetches the URL, understands the Spamhaus-DROP-style <cidr> ; <annotation> format, and skips #, ;, and // comment lines. Lines that aren't valid IPs/CIDRs are skipped, so a partially-malformed feed still loads its good rows. Its outbound fetch is SSRF-hardened by default (see the security notes below).
Fail-open semantics
Reputation is layered defense, so an unavailable feed must never block legitimate traffic:
- A failed initial load leaves an empty (permissive) denylist, so requests flow.
- A failed refresh keeps the previous, last-known-good entries for that feed. The other feeds are unaffected.
- A request that skipped your proxy chain is checked by its TCP peer. When
trustProxyHeaders,trustedHopsortrustedProxiesresolve no forwarded IP (the peer is not one of yourtrustedProxies, orX-Forwarded-Foris missing or shorter thantrustedHops), the guard checks the socket the request actually arrived on, so a listed client cannot pass just by going direct-to-origin. A denylist can only block, so this fallback never admits anyone. SetonUnresolvedIp: "allow"to let such requests through unchecked instead. - Only a request with no resolvable IP at all (a peer-less edge runtime with no
behindProxy) is treated as not-listed.
Observe feed health with onError:
Monitor mode
Roll a new feed out in "log" mode first to measure what it would block before you enforce it:
Manual refresh & introspection
ipReputation() returns a controller you can drive directly:
Custom IP resolution
With no trust option, the guard follows the App's behindProxy posture, and checks the unspoofable TCP peer when the App declares none. So ipReputation({ feeds }) on its own blocks listed peers, and behind app({ behindProxy: { cidrs } }) it checks the forwarded client only when the request came through one of those proxies. An explicit trustProxyHeaders: false keeps the TCP peer and ignores the App's posture.
Set trustProxyHeaders: true, trustedHops or trustedProxies to give the guard its own forwarded-header trust (only behind a proxy you trust to overwrite X-Forwarded-For / X-Real-IP; prefer trustedProxies when the origin can be reached directly), or pass your own resolveIp. A custom resolver that returns undefined lets the request through:
Security notes
- Defense in depth. A denylist complements (never replaces) authentication, rate limiting, and
ipRestriction()allowlists. - Trust your feeds. A compromised feed can deny legitimate clients. Prefer reputable sources and watch
onError/ match volume. - SSRF.
urlFeed()'s outbound fetch is SSRF-hardened by default: it routes through afetchGuard()instance (per-hop redirect re-validation, cloud-metadata and internal IPs blocked), so a compromised feed host can't redirect the request into internal space. OverridefetchImplonly for a non-standard runtime, or withfetchGuard({ allowPrivate: true })for an intentionally internal feed mirror. - Feed credentials stay on the feed's origin. Every header you pass in
urlFeed(url, { headers })(anx-api-key, say) is removed when a redirect leaves the feed's origin, on top of theAuthorization/Cookiestrip thatfetchGuard()always applies. Tune the default guard withguard(for exampleurlFeed(url, { guard: { allowHosts: ["feeds.internal"] } })); the header strip always applies. A customfetchImplmust strip them itself.