Login brute-force protection for /auth/password and WebDAV Basic (progressive throttling, not hard lockout) #841

Closed
opened 2026-10-03 16:37:09 +00:00 by Cordy · 3 comments
Owner

Found in the #533 QA pass (2026-10-03). This is QA finding 4.

What happens

  • No limit on wrong guesses. 30 wrong passwords in a row against POST /auth/password were each refused at about 30 ms, and the correct password still worked straight after. There is no per-account or per-IP delay, no 429 and no lockout.
  • WebDAV Basic goes through the same verifier with the same lack of limits.
  • What exists today:
    • verifyLimiter (internal/auth/limiter.go) only dedupes identical concurrent verifications and caps parallel argon2 runs. That is the #5 OOM fix, not a brute-force control.
    • The minimum password length is 10.
    • Public share passwords have their own rate limiter (internal/share/ratelimit.go), so the pattern exists in the codebase.

Research

  • OWASP (Authentication cheat sheet) prefers exponential back-off / throttling to hard lockouts. If you lock, lock for a period and reopen automatically. It also counts failures per account, so a distributed attacker can't spread guesses across IPs.
  • Nextcloud
    • How it works: per-IP progressive delay up to 25 s, and 429 after 10 attempts in 30 min. Successful logins reset the counter, and admins can whitelist ranges.
    • What went wrong:
      • Behind a reverse proxy without trusted_proxies, every user shares the proxy IP, so the whole instance gets throttled. This is the most common support thread on the topic.
      • Desktop and mobile clients retrying stale credentials keep re-triggering it.
    • Lesson: the client-IP source must be trustworthy, and unattended clients with old passwords must not lock humans out.
  • Grafana
    • How it works: per-username lockout, 5 failures in 5 min, then 5 min blocked, configurable since PR #97091.
    • What went wrong:
      • Anyone can lock the admin out on demand by failing five logins, a lockout DoS (issue #109138 and others).
      • IP-based protection is off by default, and before #97091 the attempt count was not configurable.
  • Cairn's own clientIP trusts the first X-Forwarded-For hop unconditionally, which is forgeable when exposed directly. A brute-force limiter keyed on it could be bypassed by rotating XFF. It needs a trustedProxies notion first, or it must key primarily on the account.

Plan

  1. Key the counter on the account (canonical name, see the account-names issue). Keep a secondary per-client-IP counter, used only when the IP is trustworthy.
  2. Progressive delay, not lockout.
    • Failures 1–5: no delay.
    • Then exponential (1 s, 2 s, 4 s, …), capped at 30 s per attempt.
    • After 20 failures in 15 min, answer 429 with Retry-After.
    • The correct password never gets a 429 just because of failures from other IPs. A success from a client that has never failed passes, which avoids Grafana's DoS.
    • Failures from the same IP do count against it.
  3. Reset on success. Use a sliding 15-minute window. Memory-only (restart clears it, which is acceptable), bounded LRU.
  4. WebDAV Basic goes through the same counter. Credentials that were correct earlier and later changed (#838) count as failures, so a stale client slows itself down rather than everyone.
  5. Configuration: auth.trustedProxies (CIDRs). XFF is honoured only from those. The default is empty, meaning RemoteAddr only. Document it, with the Nextcloud lesson.
  6. Audit: an auth-throttled event when the 429 threshold is crossed, plus an admin bell item, "Repeated failed sign-ins for X".

Tests

  • 6th failure is delayed;
  • 21st failure → 429 with Retry-After;
  • the correct password from a clean IP still works during an attack from another IP;
  • success resets the counter;
  • spoofed XFF from an untrusted RemoteAddr is ignored;
  • a WebDAV Basic failure counts.

Decisions for Nikola

  • Thresholds: 5 free, cap 30 s, 429 at 20/15 min.
  • Should the bell item go to admins only, or to the affected user too? Google and Microsoft notify the user.

Refs:

Found in the #533 QA pass (2026-10-03). This is QA finding 4. ## What happens - **No limit on wrong guesses.** 30 wrong passwords in a row against `POST /auth/password` were each refused at about 30 ms, and the correct password still worked straight after. There is no per-account or per-IP delay, no 429 and no lockout. - **WebDAV Basic** goes through the same verifier with the same lack of limits. - **What exists today:** - `verifyLimiter` (internal/auth/limiter.go) only dedupes identical concurrent verifications and caps parallel argon2 runs. That is the #5 OOM fix, not a brute-force control. - The minimum password length is 10. - Public share passwords have their own rate limiter (`internal/share/ratelimit.go`), so the pattern exists in the codebase. ## Research - **OWASP (Authentication cheat sheet)** prefers **exponential back-off / throttling** to hard lockouts. If you lock, lock for a period and reopen automatically. It also counts failures **per account**, so a distributed attacker can't spread guesses across IPs. - **Nextcloud** - **How it works:** per-IP progressive delay up to **25 s**, and **429** after 10 attempts in 30 min. Successful logins reset the counter, and admins can whitelist ranges. - **What went wrong:** - Behind a reverse proxy without `trusted_proxies`, every user shares the proxy IP, so **the whole instance gets throttled**. This is the most common support thread on the topic. - Desktop and mobile clients retrying stale credentials keep re-triggering it. - **Lesson:** the client-IP source must be trustworthy, and unattended clients with old passwords must not lock humans out. - **Grafana** - **How it works:** **per-username** lockout, 5 failures in 5 min, then 5 min blocked, configurable since PR #97091. - **What went wrong:** - Anyone can lock the admin out on demand by failing five logins, a lockout DoS (issue #109138 and others). - IP-based protection is off by default, and before #97091 the attempt count was not configurable. - **Cairn's own `clientIP`** trusts the first `X-Forwarded-For` hop unconditionally, which is forgeable when exposed directly. A brute-force limiter keyed on it could be bypassed by rotating XFF. It needs a `trustedProxies` notion first, or it must key primarily on the account. ## Plan 1. **Key the counter on the account** (canonical name, see the account-names issue). Keep a secondary per-client-IP counter, used only when the IP is trustworthy. 2. **Progressive delay, not lockout.** - Failures 1–5: no delay. - Then exponential (1 s, 2 s, 4 s, …), capped at 30 s per attempt. - After 20 failures in 15 min, answer **429 with Retry-After**. - The correct password **never** gets a 429 just because of failures from *other* IPs. A success from a client that has never failed passes, which avoids Grafana's DoS. - Failures from the same IP do count against it. 3. **Reset on success.** Use a sliding 15-minute window. Memory-only (restart clears it, which is acceptable), bounded LRU. 4. **WebDAV Basic** goes through the same counter. Credentials that were correct earlier and later changed (#838) count as failures, so a stale client slows itself down rather than everyone. 5. **Configuration:** `auth.trustedProxies` (CIDRs). XFF is honoured only from those. The default is empty, meaning RemoteAddr only. Document it, with the Nextcloud lesson. 6. **Audit:** an `auth-throttled` event when the 429 threshold is crossed, plus an admin bell item, "Repeated failed sign-ins for X". ### Tests - 6th failure is delayed; - 21st failure → 429 with Retry-After; - the correct password from a clean IP still works during an attack from another IP; - success resets the counter; - spoofed XFF from an untrusted RemoteAddr is ignored; - a WebDAV Basic failure counts. ### Decisions for Nikola - Thresholds: 5 free, cap 30 s, 429 at 20/15 min. - Should the bell item go to admins only, or to the affected user too? Google and Microsoft notify the user. Refs: - https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html - https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/bruteforce_configuration.html - https://dev.to/tspeedcobra/why-nextcloud-locked-me-out-of-my-own-server-and-how-trustedproxies-fixed-it-381e - https://github.com/grafana/grafana/pull/97091 - https://github.com/grafana/grafana/issues/109138
Author
Owner

Process note (Nikola, 2026-10-03): the "Decisions for Nikola" above (throttle thresholds, and whether the affected user is notified too) get asked when this issue is worked on, not before.

Process note (Nikola, 2026-10-03): the "Decisions for Nikola" above (throttle thresholds, and whether the affected user is notified too) get asked when this issue is worked on, not before.
Author
Owner

Research round 2 (2026-10-08): standards, what worked and what didn't, newer approaches

Standards

  • NIST SP 800-63B §5.2.2 caps consecutive failed attempts per account at 100. It explicitly suggests increasing wait times as the account nears the cap, CAPTCHAs, allowlisting previously successful locations, and risk-based checks, all aimed at keeping attackers from locking the real user out. The newer 800-63B-4 keeps the ceiling and allows lower limits (summary). OWASP ASVS contributors call 100 too generous against spraying (ASVS#906).
  • NIST SP 800-53 AC-7 / AC-9:
    • limit consecutive failures in a time window with an automatic response (lock, delay or notify an admin);
    • AC-9: after a successful sign-in, tell the user how many failed attempts there were since their last success (AC-7).
  • ISO 27002:2022 control 8.5 (secure authentication): don't reveal which part of a login was wrong; log successful and failed attempts (ISMS.online). Its guidance list, as far as public summaries show, also includes limiting unsuccessful attempts and showing the user failed-attempt information at the next sign-in. This needs checking against the licensed text before we cite it in docs.
  • BSI ORP.4: third-party control maps tie ORP.4 to the AC-7 pattern. The exact requirement wording needs checking in the Kompendium.

What worked and what didn't

  • Microsoft Entra smart lockout: keeps separate counters for familiar and unfamiliar locations. An attacker hammering from elsewhere doesn't lock out the user signing in from their usual place (docs). This is the newest mainstream answer to the lockout-DoS problem.
  • Keycloak:
    • Red Hat's own docs say its brute-force detection makes the server vulnerable to denial of service: attackers who know usernames can disable accounts, and in permanent mode an admin must re-enable them (Red Hat).
    • It has no per-IP counter, so password spraying (one guess per account across many accounts) passes untouched (Skycloak).
    • CVE-2021-3513: a wrong error message made brute force possible even with permanent lockout (GCVE).
  • Nextcloud and Grafana: see the first comment. Nextcloud throttled whole instances behind proxies without trusted_proxies; Grafana's per-username lockout gave anyone an admin-lockout button.
  • The attacker side today: credential stuffing (stolen pairs, one try each) and spraying stay under per-account thresholds by design. The signal is failures correlated across accounts from one source, plus breached-password checks. Passkeys remove the reusable secret and are the strongest control (overview).

Telling the user

  • MediaWiki LoginNotify:
    • a failure from an unknown device notifies after the first failure, from a known device after 5;
    • the notice never shows the attacker's IP or location (help).
  • Google Workspace challenges suspicious sign-ins first and alerts only when the challenge fails (Google).
  • Phishing caution: alerts must not carry "change your password here" links. Cairn's bell is in-app, which avoids this.

Revised proposal

  1. Familiar sources (Entra-style). For each account, remember the client addresses with a successful sign-in in the last 30 days (only trusted addresses, per auth.trustedProxies).
    • Failures from unfamiliar sources use their own budget: 5 free, then a delay doubling up to 30s, then 429 after 20 in 15 min.
    • A familiar source is never slowed or blocked by failures from elsewhere.
    • Nothing ever locks permanently, which stays far below NIST's ceiling of 100.
  2. Spray detection. Per trusted client address, across accounts: failures against more than 10 different accounts in 15 min → delay that address, raise an admin alert, write an audit event. This catches what per-account counters can't.
  3. User notice (AC-9 style, in the bell, no IPs):
    • after the next successful sign-in: "N failed sign-in attempts on your account since your last sign-in";
    • an immediate bell item if the 429 threshold is reached.
  4. Admin notice: a bell item for the 429 threshold and for spray detection; the audit log has the details, including the client address.
  5. Later, outside this issue: passkeys or WebAuthn for local accounts, and a breached-password check (k-anonymity range API, privacy-preserving). Both are worth their own research issue.
## Research round 2 (2026-10-08): standards, what worked and what didn't, newer approaches ### Standards - **NIST SP 800-63B §5.2.2** caps **consecutive failed attempts per account at 100**. It explicitly suggests increasing wait times as the account nears the cap, CAPTCHAs, allowlisting **previously successful locations**, and risk-based checks, all aimed at keeping attackers from locking the real user out. The newer 800-63B-4 keeps the ceiling and allows lower limits ([summary](https://oneuptime.com/blog/post/2026-08-29-how-to-rate-limit-mfa-code-attempts-without-creating-an-account-lockout-dos/view)). OWASP ASVS contributors call 100 too generous against spraying ([ASVS#906](https://github.com/OWASP/ASVS/issues/906)). - **NIST SP 800-53 AC-7 / AC-9:** - limit consecutive failures in a time window with an automatic response (lock, delay or notify an admin); - AC-9: **after a successful sign-in, tell the user how many failed attempts there were since their last success** ([AC-7](https://opensecurityarchitecture.org/controls/ac-07)). - **ISO 27002:2022 control 8.5 (secure authentication):** don't reveal which part of a login was wrong; log successful and failed attempts ([ISMS.online](https://www.isms.online/iso-27001/annex-a-2022/8-5-secure-authentication-2022/)). Its guidance list, as far as public summaries show, also includes limiting unsuccessful attempts and showing the user failed-attempt information at the next sign-in. This needs checking against the licensed text before we cite it in docs. - **BSI ORP.4:** third-party control maps tie ORP.4 to the AC-7 pattern. The exact requirement wording needs checking in the Kompendium. ### What worked and what didn't - **Microsoft Entra smart lockout:** keeps **separate counters for familiar and unfamiliar locations**. An attacker hammering from elsewhere doesn't lock out the user signing in from their usual place ([docs](https://learn.microsoft.com/en-us/entra/identity/authentication/howto-password-smart-lockout)). This is the newest mainstream answer to the lockout-DoS problem. - **Keycloak:** - Red Hat's own docs say its brute-force detection makes the server **vulnerable to denial of service**: attackers who know usernames can disable accounts, and in permanent mode an admin must re-enable them ([Red Hat](https://docs.redhat.com/en/documentation/red_hat_build_of_keycloak/26.0/html/server_administration_guide/mitigating_security_threats)). - It has **no per-IP counter**, so password spraying (one guess per account across many accounts) passes untouched ([Skycloak](https://skycloak.io/blog/keycloak-brute-force-ip-based-protection-gap/)). - CVE-2021-3513: a wrong error message made brute force possible even with permanent lockout ([GCVE](https://db.gcve.eu/vuln/CVE-2021-3513)). - **Nextcloud and Grafana:** see the first comment. Nextcloud throttled whole instances behind proxies without `trusted_proxies`; Grafana's per-username lockout gave anyone an admin-lockout button. - **The attacker side today:** credential stuffing (stolen pairs, one try each) and spraying stay under per-account thresholds by design. The signal is **failures correlated across accounts from one source**, plus breached-password checks. **Passkeys** remove the reusable secret and are the strongest control ([overview](https://www.huntress.com/cybersecurity-101/topic/password-spraying)). ### Telling the user - **MediaWiki LoginNotify:** - a failure from an **unknown device** notifies after the first failure, from a **known device** after 5; - the notice never shows the attacker's IP or location ([help](https://www.mediawiki.org/wiki/Help:Login_notifications)). - **Google Workspace** challenges suspicious sign-ins first and alerts only when the challenge fails ([Google](https://knowledge.workspace.google.com/admin/reports/about-admin-alerts-for-suspicious-login-activity)). - **Phishing caution:** alerts must not carry "change your password here" links. Cairn's bell is in-app, which avoids this. ### Revised proposal 1. **Familiar sources (Entra-style).** For each account, remember the client addresses with a successful sign-in in the last 30 days (only trusted addresses, per `auth.trustedProxies`). - Failures from unfamiliar sources use their own budget: 5 free, then a delay doubling up to 30s, then 429 after 20 in 15 min. - **A familiar source is never slowed or blocked by failures from elsewhere.** - Nothing ever locks permanently, which stays far below NIST's ceiling of 100. 2. **Spray detection.** Per trusted client address, across accounts: failures against more than 10 different accounts in 15 min → delay that address, raise an admin alert, write an audit event. This catches what per-account counters can't. 3. **User notice** (AC-9 style, in the bell, no IPs): - after the next successful sign-in: "N failed sign-in attempts on your account since your last sign-in"; - an immediate bell item if the 429 threshold is reached. 4. **Admin notice:** a bell item for the 429 threshold and for spray detection; the audit log has the details, including the client address. 5. **Later, outside this issue:** passkeys or WebAuthn for local accounts, and a breached-password check (k-anonymity range API, privacy-preserving). Both are worth their own research issue.
Author
Owner

Decision (Nikola, 2026-10-08): the revised proposal, as written in the research round 2 comment:

  • familiar sources (a successful sign-in in the last 30 days, trusted addresses only) are never slowed or blocked by failures from elsewhere;
  • unfamiliar sources get 5 free attempts, then a delay doubling up to 30s, then 429 after 20 in 15 min;
  • never a permanent lock;
  • spray detection: more than 10 accounts failing from one trusted source in 15 min;
  • the user is told in the bell after the next sign-in ("N failed sign-in attempts…", no IPs), and immediately when the limit is reached;
  • admins get a bell item and an audit event;
  • auth.trustedProxies, default empty.

UI: two new bell items and the user's "since your last sign-in" notice. These need a short mockup before they're built.

**Decision (Nikola, 2026-10-08): the revised proposal**, as written in the research round 2 comment: - familiar sources (a successful sign-in in the last 30 days, trusted addresses only) are never slowed or blocked by failures from elsewhere; - unfamiliar sources get 5 free attempts, then a delay doubling up to 30s, then 429 after 20 in 15 min; - never a permanent lock; - spray detection: more than 10 accounts failing from one trusted source in 15 min; - the user is told in the bell after the next sign-in ("N failed sign-in attempts…", no IPs), and immediately when the limit is reached; - admins get a bell item and an audit event; - `auth.trustedProxies`, default empty. UI: two new bell items and the user's "since your last sign-in" notice. These need a short mockup before they're built.
Cordy closed this issue 2026-10-08 18:06:19 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#841
No description provided.