Repository navigation
fix(security): key login lockout on (client IP, username), trusted-proxy hops (#2339) - #2385
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…roxies by hop count (#2339) The shared limiter counted failures per client IP only, so behind any proxy five bad passwords locked every user out, and the saiku.auth.trustForwardedFor switch trusted the attacker-controlled leftmost X-Forwarded-For entry. Three budgets now apply: (IP, username) 5, username 20, IP 50 (all within the window). X-Forwarded-For is honoured only with saiku.auth.trustedProxyHops=n, taking the n-th entry from the right. The legacy boolean is an alias for n=1. Document the settings in docs/operator-hardening.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Semantic model diffSemantic model diffNo model changes and no broken references. saiku#1434 · reproduce locally with |
juanresendiz813
left a comment
There was a problem hiding this comment.
Keying on (IP, username), taking the n-th entry from the right and no longer clearing the per-IP bucket on success are the right moves, but the new keys introduce a memory problem and the new budgets can still be skipped.
Blocking
-
blocking· Security (unbounded memory keyed on caller input) ·saiku-core/saiku-web/src/main/java/org/saiku/web/security/ratelimit/LoginRateLimiter.java:62-64,:118-139,:150-177
recordFailurestoresip + "\0" + useranduseras keys.userKey(:174-177) trims and lower-cases with no length limit, and a bucket is only removed when the same key is looked up again after the window, so a username that's never retried stays for the life of the JVM. Callers pass unauthenticated input straight in (SessionResource.java:77,90,SpringSecurityAuditListener.java:59,DemoGateResource).
Repro against the PR's own class: 50 failures with distinct 1 MiB usernames leave 100 entries and ~105M key characters held after the window; a second window doubles it. Base kept one small key per address.
Would accept all of: a bound on the username before it reaches the limiter (reject/clamp, e.g. 256 chars) or a fixed-size digest as the key; maps with access-independent expiry and a maximum size (Caffeine 3.1.8 is already in the BOM); a test that distinct usernames don't grow the maps past the bound. -
blocking· Security (Basic parsing gap) ·LoginRateLimitFilter.java:35,:47,:62-77
basicUsernamerequires the literal prefixBasicwith a space. Spring'sBasicAuthenticationConverteronly checks a case-insensitiveBasicprefix and then skips six characters, so some header spellings authenticate as a real user while the filter sees no username, andisBlocked(req, null)applies only the per-IP budget. For those requests the (IP, username) and per-username budgets are never enforced; verified against the PR's filter (429 for the normal header, 200 for the variants after the budget is exhausted).
Would accept: derive the username with Spring's converter (or mirror itssubstring(6)), and when a request carries credentials the limiter can't attribute, apply the strict per-address rule so an unparseable header is never cheaper than a parseable one. Tests for the spellings the converter accepts. -
blocking· Docs claim ·docs/operator-hardening.md:153("By default the client IP is the TCP peer")
The client-IP derivation needs another look before the docs line can claim it's caller-proof; I'll follow up separately. -
blocking· Security ·LoginRateLimiter.java:182
req.getHeader("X-Forwarded-For")returns only the first header line. A proxy that adds its own line instead of appending (HAProxy documents this and tells servers to use the last occurrence) yields two lines with the caller's first, so withtrustedProxyHops=1the caller's value is used. That breaks the docs' promise that entries left of the trusted hops are never used.
Would accept: read all values withgetHeaders, join in order, then take the n-th from the right; a test with two header lines. -
blocking· Claim vs diff ·saiku-core/saiku-web/src/main/java/org/saiku/web/security/audit/AuditLogger.java:112-124(unchanged), vsSaikuLauncher.java:247-248anddocs/operator-hardening.md:168
The PR says the audit logger was updated; it wasn't.AuditLogger.clientIpstill honours only the legacysaiku.auth.trustForwardedForand takes the leftmost entry. WithtrustedProxyHops=nevery audit line shows the proxy; with the legacy flag the limiter uses the rightmost entry and the audit trail the leftmost.
Would accept: one shared resolver used by both classes, with a test.
Non-blocking
non-blocking· Security ·LoginRateLimiter.java:142-148: a success clears the username counter for every address, so one legitimate login (or Basic auth on every request) keeps resetting the per-username budget. Clear only the (IP, username) pair on success.non-blocking· Tests ·LoginRateLimiterTest.java:85-93uses a 20 ms window and a realThread.sleep(60); inject a clock (docs/ci-flakes.md).non-blocking· Tests · no test covers the keyed calls inSessionResource,DemoGateResourceor the audit listener.- Merge note: conflicts with #2389 (and #2377, #2393) in
docs/operator-hardening.md, append-only; keep both sections.
Questions for you
question·trustedProxyHops=ncounts the immediate peer, which differs from the issue's acceptance example (itsn=1yields1.2.3.4; this code needsn=2). The spoof-resistance property is the same; which definition do you want? Either way the docs should say that settingnhigher than the real number of proxies hands the choice of key to the caller.question· The per-username budget can, by design, lock a named account out from everywhere for the window (the issue asked for it). Are 20/50 the limits you want, and should they be system properties now rather than constructor-only?
🤖 Generated with Claude Code
juanresendiz813
left a comment
There was a problem hiding this comment.
Approving. The rate-limiter points from my review are tracked in #2426 (bounding the username-keyed buckets) and #2427 (Basic header spellings, multi-line X-Forwarded-For, audit logger). The client-IP point is covered by #2414, now merged. Before it can merge it needs a rebase; keep both sections in docs/operator-hardening.md.
🤖 Generated with Claude Code
Conflict in docs/operator-hardening.md: development appended the pass-through credentials section (#2341) at the same spot. Kept both sections, development's first, separated by horizontal rules. Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
PR acceptance metricAcceptance rate: 85.7% — 420 merged / 490 decided PRs (10 still open, excluded from the denominator).
Generated by |
Summary
Login lockout is no longer keyed on the client IP alone, and
X-Forwarded-Foris only used when a trusted-proxy hop count is configured.Root cause
LoginRateLimiterkept one bucket per client-IP string, so behind a proxy (every user shares the peer address) five bad passwords locked out everyone, on every credential surface (form, Basic, XMLA, demo gate). The only mitigation,saiku.auth.trustForwardedFor, took the leftmostX-Forwarded-Forentry, which is the one the caller controls, so enabling it let a client rotate buckets at will.Fix
Usernames.canonicalize). Attempts with no username (bearer, malformed header) count against the IP budget only. A success clears the (IP, username) and username counters.SessionResource,DemoGateResource(email),SpringSecurityAuditListener(event principal),LoginRateLimitFilter(parsed from the Basic header).saiku.auth.trustedProxyHops=n(default 0 = ignoreX-Forwarded-For). The client is the n-th entry from the right; fewer than n entries falls back to the peer.saiku.auth.trustForwardedFor=trueis a deprecated alias for n=1 (note: it now uses the rightmost entry instead of the leftmost).docs/operator-hardening.md.Decision for the maintainer: the issue's example counts hops excluding the peer; I defined
nas trusted hops including the immediate peer, so one proxy that appends the client address (nginx, most ingresses) is simply1. The spoof-resistance property is the same (entries left of the n-th from the right are never used). Default limits (20 per user, 50 per IP) are constructor parameters, not yet system properties.Overlap: #2338 (merged separately), #2341 and #2345 touch SessionService/login code; each is a separate PR based on development.
Test plan
acceptance/2339/spec.jsonas the first commit. Not run locally: the launcher could not be built offline here; it is intended to be red on base (admin's Basic request is 429 afternobodyfails) and green on head. CI's spec-first proof is the check.mvn -pl saiku-core/saiku-web -am test -Dtest=LoginRateLimiterTest,LoginRateLimitFilterTest,SessionResourceTest,DemoGate*green (new unit tests cover per-user keying, case-insensitivity, cross-IP user budget, IP high-water mark, hop-count resolution, spoofed-header rotation, window expiry, Basic parsing)spotless:checkon saiku-web and saiku-launcherCloses #2339
🤖 Generated with Claude Code