Throttle failed admin password attempts per client IP - #1204
Merged
Conversation
The admin password auth endpoint (POST /admin/auth) had no rate limiting, so an attacker with network access could brute-force admin.password at full speed. See GHSA-8w47-3f5r-h9xm. Add a small, dependency-free AuthThrottle middleware that limits failed attempts per client IP within a time window (10 per minute), and wrap the auth route with it. Properties that matter for an auth endpoint: - Only failures count and the per-IP limit is checked before the password is compared, so a caller with valid credentials is not throttled - including while another source is attacking - and the response does not reveal whether a guess was correct once the limit is hit. - Each source IP is tracked independently, with the map bounded and reset per window to keep memory in check. - Forwarded headers (X-Real-IP/X-Forwarded-For) are only trusted when the socket peer is a private/loopback address (a local proxy or load balancer), so a direct client cannot spoof them to evade throttling or lock out another IP; header values are validated as IPs. This is best-effort, in-process defense in depth: the primary protection of the admin endpoint must be done at the infrastructure level (firewall rules, private network, authenticating reverse proxy), as noted at the route registration. The middleware is reusable for other endpoints via NewAuthThrottle and its Middleware method.
FZambia
force-pushed
the
security/admin-auth-throttle
branch
from
August 17, 2026 18:00
18a4189 to
519d8da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /admin/authhad no rate limiting, so an attacker with network reach could brute-forceadmin.passwordat full speed. See GHSA-8w47-3f5r-h9xm.Adds a small, dependency-free
AuthThrottlemiddleware (stdlib only) that limits failed attempts per client IP within a window (10/min) and wraps the auth route with it.Design — closes brute-force without blocking a valid login
200for a correct guess even when throttled would let an attacker test at full speed and defeat the limit).X-Real-IP/X-Forwarded-Forare trusted only when the socket peer is a private/loopback address (a local proxy or LB). A direct public client's headers are ignored, so they can't be forged to evade throttling or lock out another IP. Header values are validated/canonicalized as IPs, so junk can't inflate map keys.Works out of the box for both direct deployments (peer = real client) and behind-LB deployments (peer = private proxy → real client IP from the header), with no new config.
Best-effort by design
This is defense in depth. The route registration documents that the primary protection of the admin endpoint must be at the infrastructure level (firewall rules, private network, authenticating reverse proxy). The throttle raises the bar; it is not a substitute for restricting access.
Reuse
middleware.NewAuthThrottle(max, window, isFailure)+.Middleware(h)can wrap any auth-style endpoint; theisFailure func(int) boolpredicate (default: any4xx+) lets callers define what counts.Tests
internal/middleware/auththrottle_test.go— per-IP limiting; other IPs & successes not blocked during an attack; public peer can't spoof the header; window reset; map bounded; IP-source precedence.internal/admin/handlers_test.goTestAuthHandler_Throttled— end-to-end through the real/admin/authroute.All pass; existing admin tests unchanged.