Skip to content

fix(security): key login lockout on (client IP, username), trusted-proxy hops (#2339) - #2385

Merged
juanresendiz813 merged 3 commits into
developmentfrom
fix/2339-lockout-key
Nov 18, 2026
Merged

juanresendiz813 merged 3 commits into
developmentfrom
fix/2339-lockout-key

Conversation

@buggtb

@buggtb buggtb commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Login lockout is no longer keyed on the client IP alone, and X-Forwarded-For is only used when a trusted-proxy hop count is configured.

Root cause

LoginRateLimiter kept 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 leftmost X-Forwarded-For entry, which is the one the caller controls, so enabling it let a client rotate buckets at will.

Fix

  • Three budgets inside the window, any of which blocks: (IP, username) 5; username across IPs 20; IP across usernames 50. Username is canonicalised (Usernames.canonicalize). Attempts with no username (bearer, malformed header) count against the IP budget only. A success clears the (IP, username) and username counters.
  • Call sites pass the username: SessionResource, DemoGateResource (email), SpringSecurityAuditListener (event principal), LoginRateLimitFilter (parsed from the Basic header).
  • New saiku.auth.trustedProxyHops=n (default 0 = ignore X-Forwarded-For). The client is the n-th entry from the right; fewer than n entries falls back to the peer. saiku.auth.trustForwardedFor=true is a deprecated alias for n=1 (note: it now uses the rightmost entry instead of the leftmost).
  • Docs: new section in docs/operator-hardening.md.

Decision for the maintainer: the issue's example counts hops excluding the peer; I defined n as trusted hops including the immediate peer, so one proxy that appends the client address (nginx, most ingresses) is simply 1. 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.json as 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 after nobody fails) 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:check on saiku-web and saiku-launcher

Closes #2339

🤖 Generated with Claude Code

buggtb and others added 2 commits November 12, 2026 17:12
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>
@buggtb buggtb added the security Created by Hive for agent-filed issue provenance label Nov 12, 2026
@github-actions github-actions Bot added risk/high Change risk tier: high (see docs/risk-tiers.md) area/web docs area/launcher labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

Semantic model diff

Semantic model diff

No model changes and no broken references.

saiku#1434 · reproduce locally with saiku model diff

@juanresendiz813 juanresendiz813 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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
    recordFailure stores ip + "\0" + user and user as 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.

  2. blocking · Security (Basic parsing gap) · LoginRateLimitFilter.java:35, :47, :62-77
    basicUsername requires the literal prefix Basic with a space. Spring's BasicAuthenticationConverter only checks a case-insensitive Basic prefix and then skips six characters, so some header spellings authenticate as a real user while the filter sees no username, and isBlocked(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 its substring(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.

  3. 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.

  4. 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 with trustedProxyHops=1 the 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 with getHeaders, join in order, then take the n-th from the right; a test with two header lines.

  5. blocking · Claim vs diff · saiku-core/saiku-web/src/main/java/org/saiku/web/security/audit/AuditLogger.java:112-124 (unchanged), vs SaikuLauncher.java:247-248 and docs/operator-hardening.md:168
    The PR says the audit logger was updated; it wasn't. AuditLogger.clientIp still honours only the legacy saiku.auth.trustForwardedFor and takes the leftmost entry. With trustedProxyHops=n every 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-93 uses a 20 ms window and a real Thread.sleep(60); inject a clock (docs/ci-flakes.md).
  • non-blocking · Tests · no test covers the keyed calls in SessionResource, DemoGateResource or the audit listener.
  • Merge note: conflicts with #2389 (and #2377, #2393) in docs/operator-hardening.md, append-only; keep both sections.

Questions for you

  1. question · trustedProxyHops=n counts the immediate peer, which differs from the issue's acceptance example (its n=1 yields 1.2.3.4; this code needs n=2). The spoof-resistance property is the same; which definition do you want? Either way the docs should say that setting n higher than the real number of proxies hands the choice of key to the caller.
  2. 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 juanresendiz813 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@juanresendiz813
juanresendiz813 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into development with commit c19c3a5 Nov 18, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown

PR acceptance metric

Acceptance rate: 85.7% — 420 merged / 490 decided PRs (10 still open, excluded from the denominator).

Metric Value
Acceptance rate 85.7%
Accepted / rejected / open 420 / 70 / 10
Median time to first review (merged) 125.1 h
Median time to merge (merged) 13.7 h
Median time open (decided) 14.5 h
Mean review rounds on merged PRs 1.2
Authors with at least one merged PR 8
Author Merged Rejected Acceptance
buggtb 207 19 91.6%
app/dependabot 99 41 70.7%
juanresendiz813 94 1 98.9%
app/spicule-hive 8 1 88.9%
spicule-hive-bot 8 1 88.9%
oiacub1 2 0 100.0%
k-jm 1 3 25.0%
Prithvi1994 1 0 100.0%
laborima 0 3 0.0%
rezamuliawijaya 0 1 0.0%

Generated by scripts/pr-metrics.mjs — see docs/metrics.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/launcher area/web docs risk/high Change risk tier: high (see docs/risk-tiers.md) security Created by Hive for agent-filed issue provenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[security] Login lockout is keyed on the remote IP only, so behind any proxy five bad passwords lock every user out

2 participants