Skip to content

Middleware

A reusable policy object attached to a proxy host or a location by name. One object carries exactly one type and its matching spec.

Types

type Spec Purpose
auth AuthMiddleware Require authentication.
headers HeadersMiddleware Add/remove request/response headers.
guard GuardMiddleware Conditionally deny requests.
rate-limit RateLimitMiddleware Per-client rate limiting, per route or per host (scope).
rewrite RewriteMiddleware Request-path replacement (upstream-facing): exact, prefix or regex rules.
bouncer BouncerMiddleware Deny hook: ask an external bouncer (CrowdSec LAPI or any HTTP endpoint) whether the client IP is banned.
path-block PathBlockMiddleware Deny a request by the shape of its path: file extension, segment name or glob.

Middleware object

Every object also carries the shared keys displayName, labels, tags and disabled, documented under Common fields.

Key Type Default Required Description
name string none yes Unique name that hosts and locations reference.
type string none yes One of the types above. Selects which spec key below is read.
auth AuthMiddleware none with type: auth Spec for auth.
headers HeadersMiddleware none with type: headers Spec for headers.
guard GuardMiddleware none with type: guard Spec for guard.
rateLimit RateLimitMiddleware none with type: rate-limit Spec for rate-limit.
rewrite RewriteMiddleware none with type: rewrite Spec for rewrite.
bouncer BouncerMiddleware none with type: bouncer Spec for bouncer.
pathBlock PathBlockMiddleware none with type: path-block Spec for path-block.

AuthMiddleware (auth)

Key Type Default Required Description
identityProvider string none yes, except in client-cert and basic mode Name of an IdentityProvider. Naming one in client-cert or basic mode is an error. A dangling name is a load-time error, and the proxy listeners fail closed with 503 if one ever reaches it.
mode string the provider's type no oidc | forward-auth | auth-request | client-cert | basic. See the mode table below.
requiredRoles []string none no Roles from the provider's roleMapping that may pass: admin and user in oidc and forward-auth mode, never group names (an entry that is not a role admits no one and is reported as a config warning). Refused in auth-request mode (the IdP application binding does authorization) and in basic mode (a username carries no roles).
allowFrom []string none no CIDRs exempt from this gate, compared against the derived client IP. Valid in auth-request, client-cert and basic mode only; refused in oidc and forward-auth mode, where the gate has no bypass to honour. With mode unset the effective mode is the provider's type, so an exemption against an oidc or forward-auth provider is refused too: set mode explicitly rather than relying on the default. See Which IP allowFrom compares.
clientCertRoles map[string]string none no client-cert mode only. Maps a certificate subject (RFC 2253, or its bare common name when that contains no =) to a role that requiredRoles is checked against. requiredRoles without a mapping is refused at validation.
basic BasicAuthSpec none yes in basic mode Local credentials for basic mode. Table below. Setting it in any other mode is an error.

Auth modes

mode Identity source Notes
oidc The IdP, via a browser redirect gpm is the relying party for the host; a signed SSO cookie admits later requests.
forward-auth A trusted upstream proxy's identity headers Only headers asserted by the provider's trustedProxies are believed. Admits only a user who holds a role: a provider whose roleMapping gives no user a role refuses every request, and the config reports a warning (a forward-auth gate admits only a user with a role, but the roleMapping of identity provider "<idp>" gives no user a role, ...).
auth-request An external auth_request endpoint The auth server does authorization; requiredRoles is refused.
client-cert The TLS handshake Names no identityProvider. The host (or the host a location belongs to) must set its own tls.clientAuth (optional for a gate that exempts some networks): without it the gate admits only its allowFrom exemptions and GET /health warns, because a certificate is accepted only when the handshake verified it under this host's SNI configuration, which such a host never requests. The gate also refuses a certificate presented under another host's SNI and re-checks revocation on every request.
basic The middleware's own basic.users Names no identityProvider; HTTP basic auth against local bcrypt hashes.

Several auth gates on one route

  • All must pass. Every referenced auth middleware and inline auth block that applies to the route gates it.
  • Run order. The location's inline block, then the host's inline block, then the referenced auth middlewares last-referenced first; a location's referenced gates run before its host's. The first gate that refuses or redirects answers the request.
  • Pass-through paths. An auth-request gate's outpost pathPrefix and an oidc gate's callback /__gpm/oidc/callback are served by that gate, never gated by it. Every basic, client-cert and forward-auth gate on the route still applies its full rule there (allowFrom included); another oidc or auth-request gate applies only if it runs before the owning gate.

See Several auth gates on one route.

BasicAuthSpec (auth.basic, basic mode only)

Key Type Default Required Description
users []BasicAuthUser none yes Accepted credentials. At least one, at most 64.
users[].username string none yes Compared in full; no : or line break.
users[].passwordHash string none yes bcrypt hash ($2a$/$2b$/$2y$, 60 chars). Anything else is refused at write time.
realm string the host name no Realm in the WWW-Authenticate challenge. Printable ASCII, no " or \, at most 128 chars.
name: internal-basic
type: auth
auth:
  mode: basic
  allowFrom: [10.0.0.0/8]     # the LAN skips the password
  basic:
    realm: Internal
    users:
      - username: admin
        passwordHash: $2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/Bu

Generate a hash with htpasswd -nbB admin 'hunter2' (the part after the colon), or POST a plaintext password field instead of passwordHash and gpm hashes it server-side, on a type: auth middleware and on an inline auth block on a proxy host or one of its locations alike. A password is never stored and never returned: only the hash reaches the git-backed config and the API response. One write may carry at most 64 plaintext passwords in total, counted across a host's own block and all of its locations; users that keep their stored passwordHash do not count.

The gate behaves exactly like the deprecated access-list basic auth it replaces: same 401 and WWW-Authenticate challenge, same per-client-IP lockout after 5 failures for 15 minutes (answered identically to a wrong password, so the response is no oracle; an IPv6 client counts per /56; at most 5 password checks per client run at once, further parallel requests wait for one to finish, so a parallel burst of guesses shares the same 5 and a page load with many sub-resources is not refused), same bounded bcrypt work. The failure count is one budget per client for every route of the host that uses the same gate spec (credentials, realm, allowFrom): the host route and every location with that gate share it, so spreading guesses over location prefixes gains nothing. A route whose gate spec differs, or a deprecated access-list basicAuth next to the gate, has its own budget. It also survives a config reload as long as the gate's own spec (credentials, realm, allowFrom) is unchanged; a changed spec, a restart or removing the host starts it fresh. The failure table tracks at most 65536 clients per gate. While it is full of clients with recent failures, a client it does not track is refused (fail closed), except a client that authenticated successfully through this gate in the last 24 hours (the gate remembers the 1024 most recent): it is still checked and its failures still count, and reaching the lockout drops it from that list. What it adds is the treatment every other auth mode has: it sits at the auth position of the chain (so a rate limit, an access list and a bouncer all still run outside it), the host's custom error pages render the refusal, denials are counted, and allowFrom exempts trusted networks.

In client-cert mode the identity comes from the TLS handshake, so no identityProvider is named (setting one is an error). The gate admits a request only when the handshake verified a client certificate for this host, i.e. the host runs tls.clientAuth and the trust anchor (and its CRL, if configured) accepted the certificate; otherwise it replies 401. clientCertRoles maps a certificate subject to a role: the key is the RFC 2253 subject (CN=ops,O=Corp) or its bare common name, the value is the role requiredRoles is checked against. A common name that contains = is matched only through the full subject, so a CN cannot spell another certificate's subject and take its role. With no mapping, any verified certificate passes; with a mapping, an unmapped subject or an insufficient role gets 403. requiredRoles without a mapping is refused at validation (it could never match).

Pair it with tls.clientAuth.mode: optional so certless clients still reach the chain and this middleware is what refuses them, leaving an SSO middleware free to cover other hosts or locations.

allowFrom works here exactly as it does in auth-request mode: a client whose resolved IP falls in one of the listed CIDRs is proxied straight through: no certificate requirement and no clientCertRoles check at all. That is the "the LAN does not need a client certificate, the internet does" shape: run tls.clientAuth.mode: optional, list the LAN in allowFrom, and every other client gets 401 without a verified certificate. An exempt, certless request necessarily reaches the upstream with no client-certificate identity headers: those are set only from a handshake-verified certificate, and it has none.

name: cert-or-lan
type: auth
auth:
  mode: client-cert
  allowFrom: [10.0.0.0/8]   # LAN skips the certificate requirement

In oidc mode gpm is itself the OIDC relying party for the host.

  • Flow. An unauthenticated request is redirected to the IdP; the reserved callback path /__gpm/oidc/callback exchanges the code (PKCE + nonce) and sets a signed, stateless SSO session cookie.
  • Roles. requiredRoles is enforced through the IdP's roleMapping; with no role mapping and no required roles the gate just requires a valid login.
  • Redirect URI. Register https://<domain>/__gpm/oidc/callback on the IdP for every domain of the host. The URI never carries a port.
  • On a location. The callback path lies outside the location. gpm lets the location's gate answer it when the host carries no interactive gate, no other location covers the path, and the host's locations share one oidc gate (Gate a host with SSO).
  • Signing key. Auto-generated and persisted at <cert-dir>/sso_signing.key (0600) on first use, so sessions survive restarts. Set GPM_SSO_SIGNING_KEY to supply your own key (useful when rotating or sharing a key across instances), or GPM_SSO_SIGNING_KEY_FILE to read it from a file (it wins when set and not empty; an unreadable or empty file stops startup).

After a login the upstream receives X-Forwarded-User (the email claim, or the subject when the token has no email), X-Forwarded-Email and X-Forwarded-Groups. By default the email is asserted whether or not the IdP verified it. If an upstream keys accounts on either header and the IdP lets users change their own email, set the provider's oidc.requireVerifiedEmail: a login whose ID token lacks email_verified: true is then refused at the callback with 401 and the message "sign-in refused: the identity provider has not verified the email address of this account", so no session is issued and no unverified email reaches the upstream. A gate session issued without a verified email (before the option was turned on, or by an earlier release) is not accepted while the option is on: the user goes back through sign-in. The setting is per provider and also applies to admin sign-in through that provider.

HeadersMiddleware (headers)

Key Type Default Required Description
setRequest map[string]string none no Request headers set on the way to the upstream, overwriting whatever the client sent.
setResponse map[string]string none no Response headers set on the way back, overwriting the upstream's value. Not set-if-absent, unlike securityHeaders.
removeRequest []string none no Request headers deleted before the upstream sees them.
removeResponse []string none no Response headers deleted, only where this middleware is attached and from inside the chain, so a response an auth gate wrote ahead of it is untouched. For edge-wide removal of leaked backend headers prefer stripResponseHeaders, which runs in the reverse proxy on the upstream's own response for every response that upstream returns.

At least one of the four must be set.

  • Order: when several headers middlewares are attached, their response rules run in list order, so the later-listed middleware wins on a name both touch.
  • Interim and upgrade responses: the response rules apply to every interim 1xx and to a 101 Switching Protocols, in the same order. On a 101, rules naming Connection, Upgrade, Sec-WebSocket-Accept, Sec-WebSocket-Protocol or Sec-WebSocket-Extensions are skipped so the handshake stays intact; on other responses they apply as written.

GuardMiddleware (guard)

Key Type Default Required Description
triggers []GuardTrigger none yes At least one. A trigger fires when every field it sets matches; any firing trigger denies.
allowFrom []string none no CIDRs exempt from this guard's deny, compared against the derived client IP. See Which IP allowFrom compares.
denyStatus int 403 no Status returned when a trigger fires and the client is not exempt.

GuardTrigger (guard.triggers[])

Key Type Default Required Description
name string none no Optional label (object-name characters, at most 64). A denial by this trigger is reported to Analytics as the signature guard:<name>; unnamed triggers count under the guard denial reason only.
paths []string none no Exact request paths this trigger covers. Matching is exact, see the four path mechanisms.
methods []string none no HTTP methods this trigger covers, matched without regard to letter case. Listing GET also covers HEAD. The method compared is the one on the request line: a method-override parameter (a _method form or query field, or an X-HTTP-Method-Override header) is not read. If your backend honours such an override, list POST in the trigger as well.
queryEquals map[string]string none no Query parameters that must equal these values for the trigger to fire. See the ; note below.

A trigger with no field set matches every request, which is a deny-all guard; that is legal and occasionally what you want behind an allowFrom.

paths is byte-exact. A trigger path is compared with the normalized request path as is: case-sensitive, and a trailing slash is significant, so /admin does not cover /admin/ or /Admin. There is no folding option.

  • Backend treats /admin/ like /admin: list both in paths.
  • Backend ignores case in paths: an exact trigger cannot cover every spelling. Do not rely on a guard there; restrict the host with an access list or enforce the rule in the backend.

queryEquals and ;. A guard carrying any queryEquals trigger rejects a request whose raw query string contains a ;, with 400 (before the allow/deny decision, so allowFrom does not exempt it). gpm parses the query the modern way, where only & separates parameters, so ?a=1;direct=1 is one parameter a with the value 1;direct=1 and a direct: "1" trigger would not fire, but the raw query is forwarded to the upstream unchanged, and a backend still honouring the legacy ; separator would read direct=1 and act on it. Rather than evaluate a query it cannot read the same way the upstream will, the guard fails closed. This mirrors the same rule for ; in request paths. Guards with no queryEquals trigger are unaffected, as is every other middleware.

queryEquals and key spellings. A trigger key also matches a query parameter whose name a lenient backend reads as that key: leading spaces are dropped, the name ends at a NUL byte or before an [...] suffix, and a space, . or unmatched [ reads as _ (so ?%20direct=1, ?direct[]=1 and ?a.b=1 count as direct and a_b). A request that carries the key under more than one spelling counts as matching, like a repeated key (fail closed).

RewriteMiddleware (rewrite)

Replaces the request path on the way to the upstream. It carries three kinds of rule; at least one rule of any kind is required.

Key Type Default Required Description
replacePath map[string]string none one of Exact match: the incoming path must equal the key. Key and value must be absolute paths that satisfy the to rules below; a key may not map to itself.
prefixRules []RewriteRule none one of Prefix match on a segment boundary (the path equals from, or continues with /), so /reports never captures /reports-evil. The longest matching from wins. Max 32 rules.
regexRules []RewriteRule none one of Regex match, implicitly anchored with ^. to may reference capture groups as $1 / ${name}. Max 32 rules, max 256 characters per pattern.

RewriteRule (prefixRules[] / regexRules[])

Key Type Default Required Description
from string none yes The prefix (for prefixRules) or the pattern (for regexRules) to match.
to string none yes The replacement path, absolute and confined by the rules below.

Every to is confined, on the same rules as upstream.path. It must be an absolute path with no . or .. segment, no backslash, no ;, and no query string or fragment. The rule holds for a regex replacement template too: $1 expands at request time, so the composed path is re-cleaned and re-confined to the upstream base path before it is forwarded, and a rewritten path that still carries a path separator an upstream could re-interpret is answered 400.

The confinement is not cosmetic: a rewrite runs inside the security tiers, and middlewares:write is a narrower scope than proxy-hosts:write, so a dot segment here would let a middleware-scoped token escape the base path an operator pinned a backend into.

Evaluation order is fixed: exact, then prefix (longest first), then regex (in config order). The first match wins and no rule ever sees another rule's output, so rules cannot chain into a path nobody wrote.

  • Prefix rules replace the matched prefix and append the remainder: with from: /old, to: /new, /old/thing becomes /new/thing and /old becomes /new.
  • Regex rules replace the span matched at the start of the path and append the remainder: with from: /user/([0-9]+), to: /u/$1, /user/42/profile becomes /u/42/profile. Patterns are compiled once at config load, so a pattern that does not compile is a validation error naming the rule index, never a request-time failure. Go's regexp is RE2 (linear time, no backtracking), so a pattern cannot be made to blow up on a crafted path.
  • Never a redirect. The rewrite is internal: it mutates the proxied path in place, preserving the method and body (a POST is forwarded unchanged) and the client sees no 3xx. The query string is forwarded untouched.
  • Security position. Rewrites run innermost (closest to the upstream), so rate limiting, access lists, the bouncer, auth and guards all evaluate the ORIGINAL client path; a rewrite can never move a request past a path-scoped security control.
name: legacy-paths
type: rewrite
rewrite:
  replacePath:
    /application/o/token: /application/o/token/
  prefixRules:
    - from: /old-app
      to: /app
  regexRules:
    - from: /user/([0-9]+)
      to: /u/$1

RateLimitMiddleware (rateLimit)

Key Type Default Required Description
requests float none one of "N requests per window". Use this for limits that do not reduce cleanly to a per-second rate, e.g. 100 per 1m or 5 per 1h. Set with window.
window string none with requests Go duration string ("1s", "10s", "1m", "1h", ...) the requests count applies over.
requestsPerSecond float none one of Legacy shorthand, > 0, equivalent to requests: <value> with window: "1s". Kept for backward compatibility; new configs should prefer requests/window. Mutually exclusive with them.
burst int ceil(requests) no Token-bucket capacity: how far above the steady rate a short spike may go.
allowFrom []string none no CIDRs, IPs or @<access-list> references exempt from rate limiting entirely (no token consumed, no 429) compared against the derived client IP. @name exempts a client only when the first rule of access list name that matches it is an allow rule (cidr or fetched source set) without paths, evaluated per request like the list's own gate: a client a deny rule above that allow rule matches stays limited, and a path-scoped allow rule, the defaultAction and the geo rules exempt nobody. The list must exist, and a disabled list exempts nobody. See Which IP allowFrom compares.
blockFor string none no Go duration. Adds a fixed lockout on top of the bucket, see below. Omitted means the token bucket alone governs.
blockBackoff number none no Multiplier greater than 1. Each block a client earns after its previous block ended lasts this many times longer than the last, up to blockMax. Requires blockFor.
blockMax string 24h no Go duration. The longest a backed-off block can grow to. Must be at least blockFor.
scope string route no route or host. Which requests share one budget per client: route gives the host route and every location its own; host makes the host route and all of its locations draw on one. Not allowed on a location's own inline block.
ipv6Prefix int 64 no 48 to 64; unset or 0 means 64. Prefix length an IPv6 client is grouped by: every address in one such prefix shares one bucket. A shorter prefix stops one large delegation from spreading a flood over many buckets, but also groups unrelated customers of a provider that hands out small prefixes, so they share one budget. IPv4 clients are always keyed per address.

Exactly one of requests+window or requestsPerSecond must be set.

Enforced as a per-route, per-client-IP token bucket (capacity = burst, refill = requests/window in tokens/sec). By default every route of a host (the host route and each location prefix) has its own bucket per client, so a client spreading requests over N location prefixes gets up to N+1 times the rate; set scope: host to make one bucket per client cover the host and all of its locations. A location's own extra limit always applies to that location only. Over-limit requests get 429 Too Many Requests with a Retry-After header computed from the refill rate (a slow limit like 5 per 1h can report a Retry-After of several minutes); the request is not proxied. The bucket is keyed as follows:

  • Client IP. The derived client IP. An IPv6 client is keyed by its /64, or the ipv6Prefix set (one subscriber holds a whole /64, so a per-address key would be a fresh bucket per address).
  • Basic-auth lockout. Keys IPv4 the same way and IPv6 by the wider /56 (see Client IP and the three trust tiers).
  • Unresolvable client IP. A single shared bucket (fail-safe, never unlimited, and never matches allowFrom).
  • Bucket cap. One rate limit tracks at most 16384 client buckets; at the cap a new client evicts one, and a client whose block has ended rejoins the unblocked buckets as the most recently used one, so its streak is remembered as long as any active client's bucket. While at most half the tracked buckets are blocked, the victim is the least recently used unblocked bucket, which restarts full, so new clients that stay within their own limit never lift a block and an eviction never makes the limit stricter. While more than half are blocked, the victim is the running block that ends soonest, so a flood of addresses that each get themselves blocked can lift a block early (the shortest remaining first), but blocked buckets cannot crowd unblocked clients out of the table.
  • Zoned address. A client whose address carries a zone (an IPv6 link-local peer such as fe80::1%eth0) shares one bucket per network interface with every such peer on it, whatever address it uses. Access lists and allowFrom still treat it as having no address.
  • Position. The middleware sits outermost in the chain (evaluated first), so a flood is shed before it can drive an auth subrequest or any other per-request work: rate-limit -> path-block -> access-list -> bouncer -> auth -> guard -> headers -> rewrite -> upstream.

blockFor (a Go duration string, e.g. "30s", "5m") adds an extra, harsher penalty on top of the token bucket: the first request that exceeds the limit blocks that client for blockFor, and every request from it is rejected (429, Retry-After counting down to the end of the block) for the whole period, independent of token refill, so a client that merely pauses and resumes cannot slip back through once tokens would otherwise have refilled. The block is fixed, not sliding: repeat requests during the block do not push it back out, so it always expires exactly blockFor after the trip that started it. Once it expires, ordinary token-bucket rules resume (the bucket has been refilling in the background the whole time, up to burst, so the client gets a normal allotment, not an instant re-burst). Omit blockFor (the default) for today's behavior: only the token bucket governs, and a client that outwaits the refill rate is let back through immediately.

blockBackoff makes repeat offenders pay more each time:

  • The first block lasts blockFor. A client that trips the limit again after that block ended is blocked for blockFor * blockBackoff, then blockFor * blockBackoff^2, and so on, capped at blockMax (default 24h).
  • Requests during a block still never extend it; only a fresh trip after the block ended earns the next, longer one.
  • The streak is forgotten once the client stays within the limit for one full length of its last block, counted from the moment that block ended. A client that served a 4 minute block and then behaves for 4 more minutes starts over at blockFor.
  • The streak lives in the same per-client bucket as the tokens, so it is lost with the bucket on an eviction at the bucket cap (a running block only while more than half the table is blocked, see Bucket cap above), a restart, or a reload that changes this limit's spec, exactly like the block itself. A reload that leaves the limit's spec unchanged (including one that only changes another host) keeps the buckets, blocks and streaks.

With blockFor: 1m, blockBackoff: 2, blockMax: 1h a scanner that keeps coming back is blocked for 1m, 2m, 4m, 8m, 16m, 32m, then 1h per round.

BouncerMiddleware (bouncer)

Key Type Default Required Description
provider string crowdsec no crowdsec | http. Selects the verdict protocol.
url string none yes Base URL of the bouncer. For crowdsec, the LAPI root; for http, the endpoint that answers the query below.
apiKey Secret none no Sent as X-Api-Key. Must be a ${ENV:...} / ${FILE:...} placeholder; a literal is refused at commit.
timeout string 2s no Go duration for one verdict lookup.
cacheTTL string 60s no How long a verdict is cached per client IP. In stream mode this is also the delta-pull interval. A verdict derived from an error is capped at 5s regardless.
cacheMaxEntries int 10000 no LRU bound on the verdict cache, so a rotating-source-IP flood cannot grow it without bound.
onError string fail-open no fail-open | fail-closed. What an unanswerable lookup means, see below.
denyStatus int 403 no Status returned on a deny verdict.
denyWith string error-page no error-page renders the host's configured page for denyStatus; plain sends a bare status body, giving a scanner nothing to fingerprint.
stream bool false no crowdsec only. Pull the whole decision set once and delta it every cacheTTL, so the request hot path never calls the LAPI.
allowFrom []string none no CIDRs exempt from the external verdict, compared against the derived client IP. See Which IP allowFrom compares.

The bouncer client never follows redirects, ignores proxy environment variables and refuses a url that resolves to a link-local address (a cloud metadata service), like gpm's other outbound clients.

This is a hook, not a WAF. gpm ships no rules, no signatures and no detection engine: it asks an operator-run bouncer whether the client IP is currently banned and acts on that verdict. What "banned" means lives entirely outside gpm.

It sits after the access list and before auth: an operator allow-list still wins outright (it is evaluated first, so an explicitly allowed IP is never overridden by an external feed), and a banned IP never reaches the IdP: no forward-auth subrequest, no OIDC redirect. A denial is reported to the per-host denial counter.

crowdsec provider. Per uncached client IP, gpm calls the LAPI bouncer endpoint GET {url}/v1/decisions?ip=<client> with X-Api-Key: <apiKey>. A null or empty body means "no decisions" (allow); any decision of type ban or captcha denies. captcha is treated as a deny: it is the LAPI telling the bouncer this client must prove it is human, and gpm has no captcha flow to hand it: serving the request anyway would silently downgrade the operator's decision to an allow. Decision types gpm does not implement are ignored rather than guessed at. The LAPI resolves range (CIDR) decisions itself, so one ip= query covers those too.

stream: true (crowdsec only) swaps the per-IP lookup for a local one: gpm pulls the whole decision set once (GET {url}/v1/decisions/stream?startup=true) and then deltas every cacheTTL, keeping the banned IPs and CIDR ranges in memory, so the request hot path never calls the LAPI at all. The startup pull runs again for each config reload (the set is rebuilt with the chain). One request runs it, and every request that arrives meanwhile waits for it, at most timeout, and then gets the real verdict; a request still waiting after timeout takes the onError path, and that verdict is not cached. When the startup pull itself fails (the LAPI errors or does not answer within timeout), the requests that waited for it take onError too, and that verdict is cached like any error verdict (at most 5s). A failed startup pull, including one that panicked, is retried after a backoff (1s, doubling up to cacheTTL), and requests inside the backoff take onError at once. Refreshes happen in the background while the current set keeps serving, and a failed refresh logs and keeps the previous set rather than dropping it. Use it on a busy edge or with a large decision set; leave it off for the simpler live-lookup mode.

http provider is a generic deny hook so any custom bouncer can plug in:

GET {url}?ip=<client>&host=<host>&path=<path>
X-Forwarded-For: <client>          # the RESOLVED client IP, not the inbound header
X-Original-URL: <absolute request URL>
X-Api-Key: <apiKey>                # only when apiKey is set

path carries at most the first 1024 bytes of the request path and X-Original-URL at most the first 2048 bytes of the URL, so a long client URL cannot push the lookup past the hook server's request-line or header limits.

2xx = allow, 403 = deny, anything else = no usable answer, so onError governs. The contract is deliberately trivial: a shell script, a fail2ban shim or a corporate threat feed can implement it in a few lines.

onError covers a timeout, a connection failure, an unexpected status, an undecodable body, an unresolvable apiKey secret, and a client IP that cannot be resolved at all. It defaults to fail-open (allow): an unreachable threat feed must not take the site down, which is the opposite of the right default for auth. Choose fail-closed when the bouncer is a hard requirement and you would rather serve 403 than serve an unvetted client.

Verdicts are cached per middleware, keyed by client IP, for cacheTTL, bounded at cacheMaxEntries with LRU eviction (so a rotating-source-IP flood cannot grow it without bound). A verdict derived from an error rather than a real answer is capped at 5s regardless of cacheTTL, so an outage cannot pin a minute of guessed verdicts and keep guessing long after the bouncer recovered. For the http provider a fail-open verdict derived from an error is not cached at all (the hook's answer depends on the request, so its error can be specific to one request); a fail-closed one is cached for the 5s.

Live lookups are per client address (an IPv6 client is never judged by its neighbours' prefix), and concurrent requests that miss the cache with the same lookup share one call to the bouncer: for crowdsec the same client IP, for http the same IP, host, path and X-Original-URL. Every request sharing a call gets its verdict or its error (then onError as above); the shared call runs to its timeout even if the request that started it goes away.

denyWith: error-page (the default) renders the host's configured custom error page for denyStatus, falling back to the plain status body when none is configured; plain opts out of the custom page deliberately: a bare status body gives a scanner nothing to fingerprint.

CrowdSec quickstart. On the host running the CrowdSec LAPI:

cscli bouncers add gpm

Copy the printed key into the environment gpm runs with (e.g. CROWDSEC_BOUNCER_KEY) and reference it as a placeholder, never commit the literal:

name: crowdsec
type: bouncer
bouncer:
  provider: crowdsec
  url: http://crowdsec:8080
  apiKey: ${ENV:CROWDSEC_BOUNCER_KEY}
  stream: true          # local lookups; deltas pulled every cacheTTL
  cacheTTL: 60s
  onError: fail-open    # an unreachable LAPI must not take the site down

Verify with cscli decisions add --ip <your-test-ip> --duration 1m and confirm the host answers 403, then cscli decisions delete --ip <your-test-ip>.

# Require SSO, but let the LAN through without it
name: require-sso
type: auth
auth:
  identityProvider: authentik-outpost
  mode: auth-request
  allowFrom: [10.0.0.0/8]
# Block POSTs to a login path except from the LAN (break-glass guard)
name: login-lan-only
type: guard
guard:
  triggers:
    - {paths: [/login], methods: [POST]}
  allowFrom: [10.0.0.0/8]
# Rate-limit the host to 100 requests/minute, but let the LAN through uncapped
name: api-rate-limit
type: rate-limit
rateLimit:
  requests: 100
  window: 1m
  burst: 150
  allowFrom: [10.0.0.0/8]
# Legacy shorthand (requests per second); equivalent to requests: 10, window: 1s
name: api-rate-limit-legacy
type: rate-limit
rateLimit:
  requestsPerSecond: 10
  burst: 20
  allowFrom: [10.0.0.0/8]
# Trip the limit and the client is locked out for 5 minutes, regardless of
# token refill - not just throttled back to the steady-state rate.
name: api-rate-limit-blocked
type: rate-limit
rateLimit:
  requests: 100
  window: 1m
  blockFor: 5m
# Public site: repeat offenders are blocked twice as long each round, up to a day.
# Everything the lan-only access list allows (LAN, VPN, its fetched monitor
# feed) is never counted.
name: public-site-limit
type: rate-limit
rateLimit:
  requests: 60
  window: 1m
  allowFrom: ["@lan-only"]
  blockFor: 1m
  blockBackoff: 2
  blockMax: 24h
# Generic deny hook: any endpoint answering 2xx/403. Fail closed - this bouncer
# is a hard requirement, so an outage denies rather than admits.
name: threat-feed
type: bouncer
bouncer:
  provider: http
  url: https://bouncer.internal/check
  apiKey: ${FILE:/run/secrets/bouncer_key}
  timeout: 1s
  cacheTTL: 30s
  onError: fail-closed
  denyStatus: 403
# Add the trailing slash a client strips off Authentik's token endpoint, so the
# request reaches Django as /application/o/token/ (POST + body preserved) instead
# of getting a 405. Exact-match, upstream-facing only.
name: authentik-token-slash
type: rewrite
rewrite:
  replacePath:
    /application/o/token: /application/o/token/

PathBlockMiddleware (pathBlock)

Refuses a request by the shape of its path alone. The same spec is also settings.pathBlock, the fleet list that covers every proxy host. For a task walkthrough see Block scanner paths.

Key Type Default Required Description
extensions []string none one of extensions, names, globs File extensions with the leading dot (.php, .env, .tar.gz). Matches when any path segment ends with one, so /a.php/extra is blocked too, and when a segment is the extension alone (/.env). At most 256 entries.
names []string none one of extensions, names, globs Whole path segments (.git, wp-admin, wp-login.php). Matches any segment, directories included, at any depth. At most 256 entries.
globs []string none one of extensions, names, globs path.Match patterns over the whole path, tried on the path as it is and on the folded form described below. Each must start with /. * and ? never match /, [a-z] is a class (written in lower case), a backslash quotes the next character. There is no **. At most 64 entries, 128 bytes each and 2048 bytes for all globs of one list together.
allowFrom []string none no Clients the block does not apply to: CIDRs, bare IPs and @<access-list> references. @name exempts a client only when the first rule of access list name that matches it is an allow rule (cidr or fetched source set) without paths, evaluated per request like the list's own gate: a client a deny rule above that allow rule matches stays blocked, and a path-scoped rule, the defaultAction and the geo rules exempt nobody. The list must exist, and a disabled list exempts nobody. See Which IP allowFrom compares.
denyStatus int 404 no Status of a blocked request: 400 to 599 when set, and unset or 0 means 404. The default answers like a path that does not exist.
denyWith string error-page no error-page renders the host's custom error page for the status when one exists; plain always writes the bare status text.

Matching rules:

  • Matching is case-insensitive throughout.
  • It runs on the cleaned, decoded client path, after dot-segment and percent-decoding normalisation, and before stripPrefix, rewrite and the upstream path are applied. gpm does not decode that path a second time.
  • A segment is compared without its trailing dots and spaces, and only up to its first NUL byte, so /x.php. and /x.php%00.txt are treated as x.php.
  • A glob is tried on the lower-cased request path as it is, and on a folded form of it: cut at the path's first NUL byte as a whole (so /backup/site.zip%00/x is matched by /backup/*.zip), each segment without trailing dots and spaces, a segment that is only dots and spaces dropped, and without a trailing slash. So /server-status also blocks /server-status/ and /Server-Status.. The folded form only ever adds matches.
  • A glob must be writable in the folded form, so validation refuses one that ends with / (other than / itself), one with an empty segment (//), one with a segment ending in a dot or a space, and one with a control character. A trailing slash on a pattern is refused, not ignored: write /old, not /old/.
  • Extensions and names still look at every segment, each cut at its own first NUL byte.
  • * and ? never match /. A [...] class can: a negated class ([^x]) or a range that spans / matches a slash like any other character. A class must be written in lower case: validation refuses an upper-case letter inside a class, because the pattern is lower-cased before use.
  • /dir/* covers /dir/ and one level below it. It does not cover /dir itself, and does not cover deeper levels, because * never matches /. To block a directory at any depth use a names entry; with globs it takes both /dir and /dir/*, and still covers one level only.
  • The query string is never looked at. Every method is blocked alike.
  • A client whose address cannot be resolved is never exempt. An @list that does not resolve exempts nobody.

Limits:

  • At least one of extensions, names, globs is required.
  • Every entry is at most 128 bytes.
  • Extensions and names contain no / and no control character, and do not end with a dot or a space. An extension starts with ..
  • At most 256 extensions, 256 names and 64 globs, and 2048 bytes for all globs of one list together.
  • Entries must be valid UTF-8.
  • Long paths. On a route covered by a list that has globs, a request path longer than 4096 bytes counts as listed: it is refused with the list's denyStatus unless the client is exempt. The length is measured after lower-casing, which can lengthen a path that is not valid UTF-8. A list with only extensions and names has no such bound.

Where the step runs:

  • It sits just inside the rate limit and ahead of the access list, bouncer and authentication. See Request pipeline.
  • Maintenance mode and the forceSSL redirect run before it: a listed path on a host in maintenance gets the maintenance response, and on plain HTTP a forceSSL host answers its redirect first.
  • Blocked requests are counted with the denial reason path-block, and the access log line and GET /api/logs entry of a blocked request carry deny: path-block.
  • It is a filter on path shape, not content inspection and not a substitute for hardening the upstream.

What it does not catch:

  • Names that only a double-decoding upstream produces (/x.ph%2570).
  • Platform-specific spellings other than trailing dots and spaces, for example an NTFS stream suffix (x.php::$DATA).
  • Characters that only compare equal under Unicode case folding.
  • Content negotiation that maps another name onto a listed file (/wp-login served as wp-login.php).

gpm matches the cleaned client path and does not decode it a second time.

# Answer 404 for scanner paths on one host, except from the office network
name: scanner-paths
type: path-block
pathBlock:
  extensions: [".php", ".env", ".sql", ".bak"]
  names: [".git", ".htaccess", "wp-admin", "wp-login.php"]
  globs: ["/server-status"]
  allowFrom: [192.0.2.0/24, "@office"]
  denyStatus: 404
  denyWith: plain