List cap (F4): a server read with overrideAccess: true that passes a request on is not capped (the cookie scanner's scheduled crawl read its review list through the token request); reference types without the e2e fixtures; changelog heading covers all of 1.18.0
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e23edb2429
commit
2af8ef180f
+8
-2
@@ -9,7 +9,12 @@ versions at once, go through every "Requires project changes" section in order,
|
||||
version you have. A new release = a new section at the top; we remove the oldest ones only
|
||||
once there are more than 20.
|
||||
|
||||
## Unreleased (for 1.18.0) — two-step verification: the first set-up is confirmed by e-mail
|
||||
## Unreleased (for 1.18.0) — two-step set-up confirmed by e-mail, speed and growth, security audit fixes
|
||||
|
||||
This heading and the 1.17.2 section below (never released on its own) become one 1.18.0 entry at release. Read every
|
||||
"what changes for an existing site" list: the one here and the one in each subsection.
|
||||
|
||||
### Two-step verification: the first set-up is confirmed by e-mail (docs/security.md)
|
||||
|
||||
> **Read before upgrading — what changes for an existing site, most important first:**
|
||||
>
|
||||
@@ -101,7 +106,8 @@ once there are more than 20.
|
||||
> 1. **Public lists are capped at 100** (`listLimit`, finding F4). A REST / GraphQL list (`find`, versions, distinct
|
||||
> values) asked by a caller that is not staff gets at most 100 documents; `pagination=false` and `limit=0` become one
|
||||
> page of 100. Before, one anonymous `GET /api/posts?limit=100000` read a whole collection with its relations.
|
||||
> Staff accounts, the panel and the Local API (the frontend, seeds) are not capped. **A client-side script that reads
|
||||
> Staff accounts, the panel, the Local API (the frontend, seeds) and server code that reads with
|
||||
> `overrideAccess: true` while passing a request on (the cookie scanner's scheduled crawl) are not capped. **A client-side script that reads
|
||||
> more than 100 documents anonymously now gets the first 100 and `hasNextPage: true`** — page through, or adapt:
|
||||
> `listLimit: { max: 500 }`, `{ exclude: ['products'] }`, `{ staff: true }`; off: `listLimit: false`.
|
||||
> 2. **An operator name in `?sort=` answers 400** (`refuseOperatorSort`, F5): `$where`, `-$natural`, `title.$ne` —
|
||||
|
||||
+1
-1
@@ -1256,7 +1256,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
|
||||
| The second factor on every collection and global, whichever plugin added it, and on the plugin's endpoints; an unrecognised 2FA package = startup error | per entity: `custom.ipal.secondFactor: false` or `{ read: false }` (or the package's `custom.totp.disableAccessWrapper`); everywhere: `twoFactor.guard: false` (not recommended) | `requireSecondFactor` / `secondFactorPassed` in your own access functions and endpoints |
|
||||
| At most 5 **wrong** verify codes per account in 10 minutes (`POST /api/verify-totp` → `429`); a right code gives its place back (1.17.1), so correct logins are never refused; an attempt held out only by others still being checked gets `429` + `Retry-After: 2` ("try again in a moment"); the count is kept in memory and in the database (`payload.kv`), so a restart or a second instance does not reset it. **Verify:** log in correctly 7 times in a row → all in; 5 wrong codes → the next gets `429` with a long `Retry-After` | `twoFactor.verifyLimit: false` | `verifyLimit: { max, windowMinutes, store: 'memory' }`; own wiring: `buildVerifyLimit(...)` + `limit.settle(req, correct)` |
|
||||
| The plugin's panel actions (`POST` mail service connect / disconnect, test e-mail, cookie scan / approval / crawl) refuse a request a browser marks as coming from another origin (`403`, before anything is read; 1.17.2). The panel's buttons are not affected; set `serverURL` (doctor `csrf-empty` warns without it). **Verify:** `curl -X POST <site>/api/ipal/test-email -H 'Origin: https://other.example' -H 'Content-Type: text/plain' -b <admin cookies> -d '{}'` → `403` | `adminSameOrigin: false` | `adminSameOrigin: { origins: [...] }`; `requireOwnOrigin(endpoint, origins?)` for your own endpoints |
|
||||
| Public lists capped (1.18.0, audit F4): a REST / GraphQL list from a caller that is not staff gets at most 100 documents; `pagination=false` / `limit=0` become one page of 100; staff and the Local API untouched. **Verify:** `curl -s '<site>/api/pages?limit=100000' \| jq .limit` → `100` | `listLimit: false` | `listLimit: { max, staff, exclude }`; `buildQueryGuardHook` for a collection a plugin adds after iapl; `capListLimit` |
|
||||
| Public lists capped (1.18.0, audit F4): a REST / GraphQL list from a caller that is not staff gets at most 100 documents; `pagination=false` / `limit=0` become one page of 100; staff, the Local API and server reads with `overrideAccess: true` that pass a request on untouched. **Verify:** `curl -s '<site>/api/pages?limit=100000' \| jq .limit` → `100` | `listLimit: false` | `listLimit: { max, staff, exclude }`; `buildQueryGuardHook` for a collection a plugin adds after iapl; `capListLimit` |
|
||||
| Operator names in `sort` refused (1.18.0, audit F5): `?sort=$where`, `-$natural`, `a.$ne` → `400` for everyone (logged as one `info` line, `RefusedSortError`) instead of a database error. **Verify:** `curl -s -o /dev/null -w '%{http_code}' '<site>/api/pages?sort=%24where'` → `400` | `refuseOperatorSort: false` | `loggingLevels: { RefusedSortError: false }`; `isOperatorSort` |
|
||||
| Payload's document locks (`payload-locked-documents`) for staff accounts only, with the second factor (1.18.0); Payload's default was any signed-in account, a customer too. **Verify:** a visitor account gets `403` on `/api/payload-locked-documents`; the panel still shows who edits a document | `lockedDocuments: false` | `lockedDocuments: { access: { read, create, update, delete } }`; `staffOnlyLocks`, `applyLockedDocumentsAccess` |
|
||||
| CSP report log lines normalised (1.18.0, audit F1): origin of the blocked resource, path of the page, no control characters, every value ≤ 128 characters; at most 10 violations per request, 60 requests per client a minute (answer stays `204`) | `rateLimit: false`; your own `onReport` (gets the raw values) | `createCspReportRoute({ maxReports, rateLimit: { max, windowMs }, onReport })`, `cspLogLine` |
|
||||
|
||||
@@ -47,7 +47,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
|
||||
| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server |
|
||||
| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) |
|
||||
| `strictAccessAnswers` | `true` (1.18.0) | a project's access callback (`cookieScanner.access`, the doctor's `access`) allows only on a literal `true`; `req.user`, `1`, a string, an un-awaited Promise refuse; a non-boolean answer is reported once per option | `false` = any truthy answer allows (as before 1.18.0) |
|
||||
| `listLimit` | `{ max: 100, staff: false }` (1.18.0, audit F4) | a REST / GraphQL list (`find`, versions, distinct) from a caller that is not staff gets at most `max` documents; `pagination=false` / `limit=0` become one page; staff and the Local API untouched | `false` (Payload's behaviour); `{ max, staff: true, exclude: ['slug'] }`; `buildQueryGuardHook` for a collection added after iapl |
|
||||
| `listLimit` | `{ max: 100, staff: false }` (1.18.0, audit F4) | a REST / GraphQL list (`find`, versions, distinct) from a caller that is not staff gets at most `max` documents; `pagination=false` / `limit=0` become one page; staff, the Local API and server reads with `overrideAccess: true` that pass a request on untouched | `false` (Payload's behaviour); `{ max, staff: true, exclude: ['slug'] }`; `buildQueryGuardHook` for a collection added after iapl |
|
||||
| `refuseOperatorSort` | `true` (1.18.0, audit F5) | a `sort` naming a database operator (`$where`, `-$natural`, `a.$ne`) → `400` for everyone, logged as one `info` line (`RefusedSortError`) | `false`; `loggingLevels: { RefusedSortError: false }` hides the log line |
|
||||
| `lockedDocuments` | staff only (1.18.0) | Payload's document locks (`payload-locked-documents`) for staff accounts with the second factor; Payload's default was any signed-in account | `false` (Payload's default); `{ access: { read, create, update, delete } }` |
|
||||
| `adminSameOrigin` | on (1.17.2) | `POST` mail service connect / disconnect, test e-mail, cookie scan / approval / crawl refuse (`403`) a request a browser marks as coming from another origin; own origins: the request's host, `serverURL`, `csrf`, `cors`, `origins` | `{ origins: [...] }` adds origins; `false` = no check; any other value stops the start |
|
||||
|
||||
+4
-1
@@ -1354,7 +1354,10 @@ gets 403 on every write door.
|
||||
## Lists and sorting (`listLimit`, `refuseOperatorSort`, `lockedDocuments`, 1.18.0)
|
||||
|
||||
Three defaults for what a caller from outside (REST, GraphQL) may ask of a collection. The Local API — the frontend,
|
||||
seeds, the project's own code (`req.payloadAPI === 'local'`) — is never touched.
|
||||
seeds, the project's own code (`req.payloadAPI === 'local'`) — is never touched, and neither is a read with
|
||||
`overrideAccess: true` that server code makes while it passes an outside request on (`payload.find({ req,
|
||||
overrideAccess: true })`, e.g. the cookie scanner's scheduled crawl, which has no account): it is the server's own read,
|
||||
not the caller's. A read with `overrideAccess: false` and the caller's `req` is the caller's and is capped.
|
||||
|
||||
- **`listLimit` (security audit F4).** A list (`find`, versions, distinct values) asked by a caller that is not staff
|
||||
gets at most **100** documents per request; `pagination=false` and `limit=0` become one page of 100. Before, one
|
||||
|
||||
@@ -47,7 +47,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
|
||||
| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server |
|
||||
| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) |
|
||||
| `strictAccessAnswers` | `true` (1.18.0) | a project's access callback (`cookieScanner.access`, the doctor's `access`) allows only on a literal `true`; `req.user`, `1`, a string, an un-awaited Promise refuse; a non-boolean answer is reported once per option | `false` = any truthy answer allows (as before 1.18.0) |
|
||||
| `listLimit` | `{ max: 100, staff: false }` (1.18.0, audit F4) | a REST / GraphQL list (`find`, versions, distinct) from a caller that is not staff gets at most `max` documents; `pagination=false` / `limit=0` become one page; staff and the Local API untouched | `false` (Payload's behaviour); `{ max, staff: true, exclude: ['slug'] }`; `buildQueryGuardHook` for a collection added after iapl |
|
||||
| `listLimit` | `{ max: 100, staff: false }` (1.18.0, audit F4) | a REST / GraphQL list (`find`, versions, distinct) from a caller that is not staff gets at most `max` documents; `pagination=false` / `limit=0` become one page; staff, the Local API and server reads with `overrideAccess: true` that pass a request on untouched | `false` (Payload's behaviour); `{ max, staff: true, exclude: ['slug'] }`; `buildQueryGuardHook` for a collection added after iapl |
|
||||
| `refuseOperatorSort` | `true` (1.18.0, audit F5) | a `sort` naming a database operator (`$where`, `-$natural`, `a.$ne`) → `400` for everyone, logged as one `info` line (`RefusedSortError`) | `false`; `loggingLevels: { RefusedSortError: false }` hides the log line |
|
||||
| `lockedDocuments` | staff only (1.18.0) | Payload's document locks (`payload-locked-documents`) for staff accounts with the second factor; Payload's default was any signed-in account | `false` (Payload's default); `{ access: { read, create, update, delete } }` |
|
||||
| `adminSameOrigin` | on (1.17.2) | `POST` mail service connect / disconnect, test e-mail, cookie scan / approval / crawl refuse (`403`) a request a browser marks as coming from another origin; own origins: the request's host, `serverURL`, `csrf`, `cors`, `origins` | `{ origins: [...] }` adds origins; `false` = no check; any other value stops the start |
|
||||
|
||||
+10
-1290
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,8 @@ import { secondFactorPassed } from './totp/secondFactor.js'
|
||||
* Payload's document locks closed to visitor accounts (the "document locks" door). Each is on by default, each can be
|
||||
* turned off or adapted, and every piece is exported for a project's own use (docs/security.md "Lists and sorting").
|
||||
*
|
||||
* Local API calls (`req.payloadAPI === 'local'`: the frontend, seeds, the project's own code) are never touched.
|
||||
* Local API calls (`req.payloadAPI === 'local'`: the frontend, seeds, the project's own code) are never touched, nor
|
||||
* is a read with `overrideAccess: true` that server code makes while passing an outside request on.
|
||||
*/
|
||||
|
||||
export type ListLimitOptions = {
|
||||
@@ -92,6 +93,9 @@ export function buildQueryGuardHook(options: {
|
||||
throw new RefusedSortError()
|
||||
}
|
||||
if (!limit || list.id != null || limit.exclude?.includes(collection.slug)) {return args}
|
||||
// A read that bypasses access is the server's own (the plugin's or the project's code passing the request on, e.g.
|
||||
// the cookie scanner's scheduled crawl, which has no account): never capped. REST and GraphQL never set it.
|
||||
if ((args as { overrideAccess?: unknown }).overrideAccess === true) {return args}
|
||||
if (!limit.staff && isStaffRequest(req)) {return args}
|
||||
return capListLimit(list, limit.max)
|
||||
}) as CollectionBeforeOperationHook
|
||||
|
||||
@@ -45,6 +45,18 @@ beforeAll(async () => {
|
||||
{ slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media') } },
|
||||
],
|
||||
db: testDatabase('query_guard'),
|
||||
// the server's own read on behalf of a request without an account (the cookie scanner's scheduled crawl does this)
|
||||
endpoints: [
|
||||
{
|
||||
handler: async (req) => {
|
||||
const all = await req.payload.find({ collection: 'notes' as never, depth: 0, limit: 0, overrideAccess: true, pagination: false, req })
|
||||
const asCaller = await req.payload.find({ collection: 'notes' as never, depth: 0, limit: 0, overrideAccess: false, pagination: false, req })
|
||||
return Response.json({ all: all.docs.length, asCaller: asCaller.docs.length })
|
||||
},
|
||||
method: 'get',
|
||||
path: '/own-read',
|
||||
},
|
||||
],
|
||||
editor: lexicalEditor(),
|
||||
plugins: [iapl({ access: { authCollection: 'users' }, i18n: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] }, twoFactor: false })],
|
||||
secret: 'integration-test-secret-0123456789',
|
||||
@@ -81,6 +93,11 @@ describe('F4: public lists are capped for callers that are not staff', () => {
|
||||
expect((await payload.find({ collection: 'notes' as never, limit: 1000 })).docs).toHaveLength(130)
|
||||
})
|
||||
|
||||
test('a read that bypasses access, inside a request without an account, is the server\'s own: not capped', async () => {
|
||||
const res = await fetch(`${base}/api/own-read`, { headers: { origin: base } })
|
||||
expect(await res.json()).toEqual({ all: 130, asCaller: 100 })
|
||||
})
|
||||
|
||||
test('GraphQL lists from outside are capped as well', async () => {
|
||||
const res = await fetch(`${base}/api/graphql`, { body: JSON.stringify({ query: '{ Notes(limit: 100000) { docs { id } } }' }), headers: { 'content-type': 'application/json', origin: base }, method: 'POST' })
|
||||
const body = (await res.json()) as { data?: { Notes?: { docs: unknown[] } } }
|
||||
|
||||
@@ -249,6 +249,7 @@ describe('denial of service and injection — lists from outside (F4, F5)', () =
|
||||
it('F4: staff, the Local API, one document by id and listLimit: false are left alone; max / exclude / staff adapt it', () => {
|
||||
expect(run({ limit: 5000 }, staff)).toEqual({ limit: 5000 })
|
||||
expect(run({ limit: 5000 }, { ...visitor, payloadAPI: 'local' })).toEqual({ limit: 5000 })
|
||||
expect(run({ limit: 0, overrideAccess: true, pagination: false }, visitor)).toEqual({ limit: 0, overrideAccess: true, pagination: false })
|
||||
expect(run({ id: 'a', limit: 5000 }, visitor)).toEqual({ id: 'a', limit: 5000 })
|
||||
expect(run({ limit: 5000 }, visitor, 'read', buildQueryGuardHook({ listLimit: false }))).toEqual({ limit: 5000 })
|
||||
expect(run({ limit: 5000 }, visitor, 'read', buildQueryGuardHook({ listLimit: { max: 20 } }))).toMatchObject({ limit: 20 })
|
||||
|
||||
Reference in New Issue
Block a user