Gate forwarded-header trust behind trusted-proxy config in rate limiters #88
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Tracking issue from the PR #87 review (advisory, non-blocking there because it matches the agreed plan and the existing
LoginRateLimitpattern).Problem
Both
ReceiverRateLimitandLoginRateLimit(internal/middleware/ratelimit.go) key onhttprate.KeyByRealIP, which trustsTrue-Client-IP,X-Real-IP, and the firstX-Forwarded-Forentry unconditionally. The first XFF entry is client-controlled even behind an appending reverse proxy, so a deliberate attacker can:REPO_POLICIES.mdrequires trusted-proxy-gated forwarded-header handling before 1.0.Definition of done
RemoteAddr) is within a configured trusted-proxy set (env-configured CIDR list; set-but-unparseable value aborts startup, per repo policy). Otherwise the key isRemoteAddr.Minor cleanups to fold in (same files, from the same review)
internal/config/config_test.go: theRECEIVER_RATE_LIMITerror-path tests assert onlyassert.Error; tighten toErrorContains(variable name in the message) /errors.Is(config.ErrNonPositiveValue).internal/middleware/ratelimit.go: the two 429 limit-handler bodies are near-duplicates; extract a shared helper.Scope note: the PR #83 review found the same unconditional forwarded-header trust in the new
PasswordChangeRateLimit(added in commit8362ce9, shares thepostRateLimithelper withLoginRateLimit). This issue covers ALL rate limiters — receiver, login, and password change — via the one shared key function described in the DoD.