Documentation
¶
Overview ¶
Package ipaccess allows or blocks requests by the client's IP address, given as literals, CIDR blocks or ranges.
Its entry point is New(allowed, blocked []string) (Handler, error), which reports a malformed pattern; Must(allowed, blocked) is the panicking companion.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Must ¶
Must is New for a caller that has nothing to do with a malformed pattern: it panics instead of reporting one, so a registration stays a single expression.
app.Use(ipaccess.Must([]string{"127.0.0.1", "10.0.0.0/8"}, nil))
The patterns are usually literals or configuration read at startup, and a bad one there is a broken deployment rather than a request-time failure. Use New when they come from somewhere that can be wrong at run time.
func New ¶
New returns a middleware that allows or blocks requests by client IP address.
An empty "allowedPatterns" means "allow everything that is not blocked"; a non-empty one means "allow only these".
SECURITY WARNING: the client IP comes from Context.Addr, which returns the FIRST entry of the first configured Options.RemoteAddrHeaders header - a value the client writes.
If your application sets RemoteAddrHeaders (the usual "behind a proxy" setup), you MUST terminate every request at a proxy that OVERWRITES that header. Otherwise any caller can send
X-Forwarded-For: 10.0.0.1
and walk straight through an admin allowlist. Iris has no trusted-proxy list yet, so this middleware cannot verify it for you.
Addr is used rather than RemoteAddr on purpose: RemoteAddr skips private subnets while walking the header chain, which would make it impossible to allowlist internal addresses - the main thing this middleware is for.
Types ¶
This section is empty.