security

package
v0.7.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

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 InZone

func InZone(name string, zone string) bool

InZone checks if name is at or below zone.

func IsReservedIP added in v0.6.2

func IsReservedIP(ip net.IP) bool

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

func SanitizeBailiwick(msg *dns.Message, zone string)

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.

func SipHash24 added in v0.6.0

func SipHash24(key [16]byte, msg []byte) uint64

SipHash24 computes a SipHash-2-4 MAC for the given message using a 128-bit key. Used by RFC 9018 for DNS server cookie generation.

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 NewACL

func NewACL(allow, deny []string) (*ACL, error)

NewACL creates an ACL from allow and deny CIDR lists.

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) Check

func (acl *ACL) Check(ipStr string) bool

Check returns true if the IP is allowed by the global ACL rules.

func (*ACL) CheckWithZone

func (acl *ACL) CheckWithZone(ipStr string, qname string) bool

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 NewRRL

func NewRRL(responsesPerSecond float64, slipRatio, ipv4Prefix, ipv6Prefix int) *RRL

NewRRL creates a new Response Rate Limiter.

func (*RRL) AllowResponse

func (r *RRL) AllowResponse(sourceIP string, qname string, responseType string) RRLAction

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.

const (
	RRLAllow RRLAction = iota
	RRLDrop
	RRLSlip // send TC=1 truncated 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

type ZoneACL struct {
	Zone      string
	AllowNets []*net.IPNet
	DenyNets  []*net.IPNet
}

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

type ZoneACLConfig struct {
	Zone  string
	Allow []string
	Deny  []string
}

ZoneACLConfig is the configuration input for a per-zone ACL rule.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL