Documentation
¶
Index ¶
- Constants
- func FilterPrivateAddresses(answers []dns.ResourceRecord) []dns.ResourceRecord
- func InZone(name string, zone string) bool
- func IsReservedIP(ip net.IP) bool
- func SanitizeBailiwick(msg *dns.Message, zone string)
- func SipHash24(key [16]byte, msg []byte) uint64
- type ACL
- type RRL
- type RRLAction
- type RateLimiter
- type ZoneACL
- type ZoneACLConfig
Constants ¶
const MaxRateLimiterClients = 1_000_000
MaxRateLimiterClients caps the number of distinct client IPs the per-IP rate limiter will track at once. Before v0.7.65 the map grew without bound: an attacker spoofing UDP source IPs can send DNS queries from millions of distinct apparent sources from a single host, and each unique IP lazily creates a tokenBucket entry. The cleanup tick runs every 5 minutes (StartCleanup) and only evicts entries idle for longer than the cleanup window — between ticks the map can grow into resolver RAM. 1M tracked clients is far above any realistic legitimate population (even a busy ISP-side resolver sees tens of thousands of concurrent distinct clients) and small enough that the worst-case footprint stays bounded to a few hundred MB. When the cap is reached, Allow evicts the OLDEST (least recently used) bucket to make room for the new client. Eviction does not degrade security: an attacker who can already spoof unlimited distinct source IPs already gets fresh per-IP budget on every request; the cap only closes the memory growth, not the per-IP isolation.
Variables ¶
This section is empty.
Functions ¶
func FilterPrivateAddresses ¶
func FilterPrivateAddresses(answers []dns.ResourceRecord) []dns.ResourceRecord
FilterPrivateAddresses removes A/AAAA records that contain private, loopback, link-local, multicast, broadcast, CGNAT, TEST-NET, IPv4-mapped IPv6, NAT64, 6to4, documentation, or otherwise non-publicly-routable addresses. Prevents DNS rebinding attacks where an external domain resolves to an internal IP.
func IsReservedIP ¶ added in v0.6.2
IsReservedIP reports whether ip falls in any non-publicly-routable range recognized by FilterPrivateAddresses. Exposed for use elsewhere in the codebase (e.g. ACL checks, metrics dimensions).
func SanitizeBailiwick ¶
SanitizeBailiwick removes records from a DNS response that are outside the authority of the responding nameserver's zone.
Out-of-bailiwick glue (e.g. a `.com` server returning glue for `ns.evil.org` to back an example.com delegation) is dropped: an out-of-zone responder has no authority to bind a hostname to an address. Such records must be re-resolved through the proper chain of authority. RFC 8499 §7 / RFC 1034 §4.2.1.
When zone is empty (the priming/root case), the filter is permissive: the root server is allowed to publish glue for any TLD nameserver, since that is exactly its job.
Types ¶
type ACL ¶
type ACL struct {
// contains filtered or unexported fields
}
ACL implements access control list based on CIDR ranges, with optional per-zone overrides.
func (*ACL) AddZoneACL ¶
func (acl *ACL) AddZoneACL(cfg ZoneACLConfig) error
AddZoneACL adds a per-zone access control rule. Zone-specific rules are checked before global rules when using CheckWithZone.
func (*ACL) CheckWithZone ¶
CheckWithZone returns true if the IP is allowed for queries to the given qname. It first looks for a matching zone-specific rule. If one is found, only that zone's allow/deny lists are evaluated. If no zone matches, the global rules are used.
type RRL ¶
type RRL struct {
// contains filtered or unexported fields
}
RRL implements Response Rate Limiting to prevent DNS amplification attacks.
func (*RRL) AllowResponse ¶
AllowResponse checks if a response should be allowed, dropped, or slipped.
func (*RRL) StartCleanup ¶
func (r *RRL) StartCleanup(ctx interface{ Done() <-chan struct{} })
StartCleanup removes stale RRL entries periodically.
type RRLAction ¶
type RRLAction int
RRLAction represents the action to take for a rate-limited response.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements per-IP token bucket rate limiting.
func NewRateLimiter ¶
func NewRateLimiter(rate float64, burst int) *RateLimiter
NewRateLimiter creates a new per-IP rate limiter.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(clientIP string) bool
Allow checks if a request from clientIP should be allowed.
func (*RateLimiter) StartCleanup ¶
func (rl *RateLimiter) StartCleanup(ctx context.Context)
StartCleanup removes idle clients periodically.
type ZoneACL ¶
ZoneACL defines access control rules scoped to a specific DNS zone. When a query matches a zone, these rules are evaluated instead of the global allow/deny lists.
type ZoneACLConfig ¶
ZoneACLConfig is the configuration input for a per-zone ACL rule.