Staff sign-in rules: failures per IP and address, own origin, current password for own changes (1.18.0)
Q2 (IAWL idea 16): Payload locks a staff account after 5 wrong passwords from anybody, so a stranger kept the owner out without a password. Failed sign-ins are now counted per client IP and typed address (folded: NFKC, lower case, trim): 5 in 15 min, then 429 for that IP and address only; only failures count (a place taken before the compare, given back on success or refusal; "try again in a moment" while others are being checked). Payload's own lock stays as the net at 50 failures for an hour where the project set none. The mail service's account-mail limit now counts per address per visitor (5) with 20 per address in all, so one stranger no longer blocks the owner's own reset mail. Q3 (idea 7): staff login, forgot and reset password refuse a request a browser marks as coming from another origin (403 before anything is counted or sent); visitor collections untouched. Q5 (idea 29): an account that changes its own e-mail, username or password must send its current password (panel field on the account page via the plugin's MaskedField, no import-map change; REST and GraphQL). Admins changing others, server code and API keys are not asked; wrong ones count like failed sign-ins. Options accounts.signInLimit / signInSameOrigin / confirmOwnChanges, all validated at start. Tests: 15 HTTP tests (2FA on/off, all off), fail before on 1.17.1; built-site spec own-account.spec.ts in e2e:built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fc70a34f3e
commit
52710021ef
+69
-1
@@ -250,6 +250,9 @@ iapl({
|
||||
// accounts: { firstUserRoute: 'all' }, // Payload's first-user route for every empty auth collection
|
||||
// accounts: { firstUserRoute: ['users', 'partners'] },
|
||||
// accounts: { password: { minLength: 16 } }, // or password: false
|
||||
// accounts: { signInLimit: { perAddress: 10, windowMinutes: 15 } }, // or signInLimit: false (Payload's lock as before)
|
||||
// accounts: { signInSameOrigin: { origins: ['https://panel.example.com'] } }, // or signInSameOrigin: false
|
||||
// accounts: { confirmOwnChanges: false }, // own e-mail / password without the current password (as before)
|
||||
// accounts: false, // none of the rules
|
||||
})
|
||||
```
|
||||
@@ -477,10 +480,75 @@ characters."; texts `passwordTooShort`, `passwordIsEmail` in `i18n.translations.
|
||||
`DEFAULT_PASSWORD_MIN_LENGTH`.
|
||||
- **Check:** create an account with an 11-character password → "The password must have at least 12 characters.".
|
||||
|
||||
### A stranger cannot lock a staff account out (`accounts.signInLimit`, 1.18.0)
|
||||
|
||||
Payload locks an account after `maxLoginAttempts` wrong passwords (5) for `lockTime` (10 minutes) — wrong passwords
|
||||
from **anybody**: five posts with no password at all kept the owner out, again and again. Now failed sign-ins to a
|
||||
staff collection are counted **per client IP and typed address**: after **5 failures in 15 minutes** from one IP for
|
||||
one address, that IP gets `429` ("Too many failed sign-ins to this address from here. Try again in N min.") for that
|
||||
address; the owner, from anywhere else, signs in. Payload's own per-account lock stays as the net against a spray
|
||||
from many IPs, at **50 failures, locked for an hour** — set only where the project did not set
|
||||
`auth.maxLoginAttempts` / `auth.lockTime` itself (a value you wrote stays; no schema change).
|
||||
|
||||
- **Only failures count.** A sign-in takes its place before the password is compared (a burst cannot slip under the
|
||||
limit) and gives it back when it worked, or when it was refused without a compare. Several correct sign-ins at once
|
||||
from one place may hear "try again in a moment" — nothing is locked.
|
||||
- **One count for every spelling** of an address: the typed address is folded like the database that folds the most
|
||||
(case, full-width and compatibility forms — NFKC — and spaces), so `OWNER@…`, `owner@…` and `owner@…` share it.
|
||||
The "too many" answer is the same for a real and an invented address.
|
||||
- **The client IP** is `clientIp()` — pin `IAPL_IP_HEADER` in production ([forms.md](./forms.md)). Requests without
|
||||
an address share one bucket at 20× the limit (`setUnknownIpFactor`). Server code (the Local API) is never limited.
|
||||
- **Options:** `signInLimit: { perAddress, windowMinutes, accountLock: { maxLoginAttempts, lockTime } }`;
|
||||
`accountLock: false` = Payload's lock (5, 10 min) beside the per-IP count; `signInLimit: false` = no per-IP count
|
||||
and Payload's lock as before. Values that make no sense (`0`, `'false'`) stop the start.
|
||||
- **Check:** five wrong passwords for an editor with `X-Forwarded-For: 198.51.100.1` (behind one proxy, with
|
||||
`IAPL_IP_HEADER=x-forwarded-for`), then the right one from there → `429`; from `203.0.113.1` → `200`.
|
||||
- A staff collection a plugin listed after `iapl` adds is not covered (its config is built after these rules).
|
||||
|
||||
### Staff sign-in only from the site's own origin (`accounts.signInSameOrigin`, 1.18.0)
|
||||
|
||||
Login, "forgot password" and "reset password" of a staff collection refuse (`403`, before anything is counted or sent)
|
||||
a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`) — over REST and GraphQL.
|
||||
A foreign page could otherwise sign a visitor's browser into an account of the attacker's choosing (login CSRF), or
|
||||
make visitors' browsers ask for reset mails. Own origins: the request's host (`Host`, `X-Forwarded-Host`),
|
||||
`serverURL`, Payload's `csrf` and `cors` lists, and `signInSameOrigin.origins`. A request with neither header (a
|
||||
script, `curl`, a server) passes. Visitor collections (not staff) are not touched — a shop front end on another
|
||||
domain keeps signing its customers in. The first refusal of each origin is logged with the ways to allow it.
|
||||
|
||||
- **A panel or front end that signs staff in from another origin:** `signInSameOrigin: { origins: ['https://…'] }`.
|
||||
**Behind a proxy that rewrites `Host`** without `serverURL`: set `serverURL` (or the site's own sign-in is refused).
|
||||
- **Off:** `signInSameOrigin: false`.
|
||||
- **Check:** `curl -X POST <site>/api/users/login -H 'Origin: https://other.example' -H 'Content-Type: application/json'
|
||||
-d '{"email":"a@b.c","password":"x"}'` → `403`.
|
||||
|
||||
### Changing one's own e-mail or password asks for the current password (`accounts.confirmOwnChanges`, 1.18.0)
|
||||
|
||||
A stolen session alone could take an account over: change the e-mail, then "forgot password". Now an account that
|
||||
changes its **own** e-mail address, username or password must send its current password — in the panel a
|
||||
**Current password** field on the account's own page (the plugin's `MaskedField`, already in every site's import
|
||||
map: no `generate:importmap`), over REST / GraphQL `currentPassword` in the body / `data`. Without it: `400` on the
|
||||
`currentPassword` field ("Enter your current password…"); wrong: `400` ("The current password is not right."). Wrong
|
||||
current passwords count like failed sign-ins (`signInLimit`). The field is virtual: never stored, never read back.
|
||||
|
||||
- **Not asked:** an administrator changing **another** account; other fields of one's own account; server code
|
||||
(`overrideAccess`); a request with an API key; "forgot password" / "reset password" (the token is the proof).
|
||||
- **Scripts that change their own password** add `"currentPassword": "<the old one>"` to the body.
|
||||
- **Off:** `confirmOwnChanges: false`. A project with its own `currentPassword` field keeps its field and its value (the
|
||||
rule reads the value from it and does not take it out of the save).
|
||||
- The check uses Payload's stored hash formats (PBKDF2-SHA256 at 600,000 / 100,000 iterations, and the older
|
||||
25,000-iteration hashes); a hash format a later Payload adds is refused until IAPL knows it (fail closed — the
|
||||
user then changes the password through "forgot password").
|
||||
- **Check:** as an editor, `PATCH /api/users/<own id>` with `{ "email": "new@…" }` → `400`; with `"currentPassword"`
|
||||
→ `200`. In the panel: Account → the new e-mail and "Current password" → saved.
|
||||
- **Building blocks** of the three rules: `applySignInRules(collection, accounts)`, `buildSignInBeforeOperation`,
|
||||
`releaseSignInPlace` (`afterLogin`), `settleFailedSignIn` (config `afterError`), `buildCurrentPasswordField`,
|
||||
`resolveSignInRules`, `foldSignInName`, `passwordMatches`, `CURRENT_PASSWORD_FIELD`; `releaseRateLimit` (gives a
|
||||
place of `consumeRateLimit` back — for limiters that count failures only).
|
||||
|
||||
## Turn off, override, extend
|
||||
|
||||
- **Account rules:** `accounts: false`, or one by one — `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`,
|
||||
`staffOnlyRead`, `firstUserRoute`, `password` (above).
|
||||
`staffOnlyRead`, `firstUserRoute`, `password`, `signInLimit`, `signInSameOrigin`, `confirmOwnChanges` (above).
|
||||
- **Turn off:** leave out `access` — no `roles` field, the auth collection keeps Payload's rules
|
||||
(or yours). `access.firstUserAdmin: false` stops giving admin to the first account.
|
||||
- **Override:** `access.staffCollections` (who is staff), `access.authAccess` (injected collection), your own auth collection (wins whole),
|
||||
|
||||
Reference in New Issue
Block a user