Repository navigation
fix(databases): require an API key or privileged user for bulk writes - #15235
Conversation
Bulk update, upsert and delete are documented as admin/API-key only, but only bulk create enforced it. The other three shared the write scope with the single-record routes, so a client session reached the action and was stopped only because the unskipped database lookup happened to return 404. Those actions also skip the checks the single-record routes rely on for sessions: granted roles, read-only timestamps and the disabled switch. Refuse non-key, non-privileged callers up front with the same general_unauthorized_scope bulk create returns, so the contract no longer rests on an incidental lookup failure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR restricts bulk write operations to API-key or privileged users: all twelve bulk endpoints (Delete/Update/Upsert across the four database service variants) now refuse session-authenticated callers with a 401 before any data mutation, and a new e2e test pins the refusal contract on the client side while verifying success on server and console sides. The gate is consistently placed as the first statement in each action, and the e2e assertions detect partial mutation for each verb. One minor inconsistency remains: the transaction bulk-operations gate uses a different error code than the bulk endpoints. Reviewed commit: 1454c02 |
🟢 Tier S · Ready to merge
Adds an explicit API-key-or-privileged-user check to the Legacy bulk update, upsert, and delete actions, and injects the required auth context into their DocumentsDB, TablesDB, and VectorsDB routes. Adds an end-to-end test covering rejected session writes and successful server/console writes across the database API variants.
📂 Walkthrough · 13
Reviewed |
Security rulesWARNING (2 new) — review signal only; does not fail the job.
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
Bulk update, upsert and delete (Legacy, TablesDB, DocumentsDB and VectorsDB) are documented as admin/API-key only (
auth: [AuthType::ADMIN, AuthType::KEY]), but that label only feeds the SDK spec. They sharedocuments.write/rows.writewith the single-record routes, and guests and members hold those scopes. Bulk create is the only bulk route that refused sessions at runtime.This adds the same up-front check bulk create uses (
isKey || isPrivileged, otherwisegeneral_unauthorized_scope) to the three base actions, and injectsuser+authorizationinto all twelve route classes.Exposure today
Checked against a running stack: on
maina session calling bulk update/upsert/delete gets404 database_not_found. The actions read the database metadata withoutauthorization->skip(), so the session can't see it and the request stops before any write. Nothing is changed (title,$permissions,$createdAtand the row count stay the same). So this isn't exploitable right now. It only holds because that lookup happens to fail. Past that lookup, the bulk paths skip the three checks the single-record routes make for sessions:$permissionsare only format-validated, not checked against the caller's rolesremoveReadonlyAttributes(..., privileged: true)lets$createdAt/$updatedAtthroughAdding
skip()to that lookup, as the single-record routes have, would expose all three. With this PR the contract is enforced explicitly.Test Plan
New
testBulkWritesRequireKeyOrPrivilegedUserinDatabasesBase, run locally on Legacy, TablesDB and DocumentsDB × custom client / custom server / console:401 general_unauthorized_scope; the record's title, permissions and$createdAtand the row count are unchangedWith the
src/change reverted, the client suites fail (404 is identical to 401on bulk update). Also re-ran locally: VectorsDBtestBulk*, GraphQL Legacy/TablesDB client+servertestBulk*,testBulkOperators,testListDocumentsCacheBustedByDocumentPermissionChange. Pint and PHPStan (phpstan.neon) clean.Related PRs and Issues
Reported internally (Discord, bulk writes with permissions).
Checklist
🤖 Generated with Claude Code