Lock order_lines writes (they were public)
order_lines had empty create/update/delete rules, so anyone could forge, edit or delete the line items of real orders through the REST API. Writes are now superuser-only (migration + pb_schema.json). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
bcb6cf80c7
commit
1f929c68ca
8 changed files with 36 additions and 263 deletions
33
pocketbase/pb_migrations/1791331200_lock_order_lines.js
Normal file
33
pocketbase/pb_migrations/1791331200_lock_order_lines.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// order_lines was writable by anyone (create/update/delete rules were empty
|
||||
// strings = public), so the line items of real orders could be forged or
|
||||
// deleted through the REST API. Orders are now created by the shop hooks
|
||||
// (pb_hooks/shop), which bypass API rules, so writes are superuser-only.
|
||||
|
||||
function find(app, name) {
|
||||
try {
|
||||
return app.findCollectionByNameOrId(name);
|
||||
} catch (e) {
|
||||
return null; // fresh install: pb_schema.json (already fixed) is imported later
|
||||
}
|
||||
}
|
||||
|
||||
migrate(
|
||||
(app) => {
|
||||
const collection = find(app, 'order_lines');
|
||||
if (!collection) return;
|
||||
collection.createRule = null;
|
||||
collection.updateRule = null;
|
||||
collection.deleteRule = null;
|
||||
app.save(collection);
|
||||
},
|
||||
(app) => {
|
||||
const collection = find(app, 'order_lines');
|
||||
if (!collection) return;
|
||||
collection.createRule = '';
|
||||
collection.updateRule = '';
|
||||
collection.deleteRule = '';
|
||||
app.save(collection);
|
||||
}
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue