PocketBase: close public sign-up, lock commerce writes, add dates/unique keys
Security: - PocketBase's default `users` collection allows anonymous sign-up, and every CMS rule only checks "signed in" (the admin login also accepts `users`). Anyone could register via the public API and edit the site, read orders/customer details, or log into the admin. Sign-up is now superuser-only. - orders.create, baskets.create/update and basket_lines.create/update/ delete were open to anonymous requests, allowing forged "paid" orders in the admin and basket tampering. The public app performs all of these server-side with the admin client, so they are now superuser-only (basket add-item/add-slot verified still working). Data: - created/updated autodate fields on all app collections; orders are now listed newest-first by date (ids are random, '-id' was not chronological). - Unique indexes on pages.slug and globals.key (skipped with a log line if existing data has duplicates, so PocketBase still starts). Delivered as a JS migration in pocketbase/pb_migrations, mounted into the container (the image already passes --migrationsDir=/pb_migrations), so it applies once on the next start. pb_schema.json carries the same changes for fresh installs, where the migration runs before the schema is imported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
af7b4af5de
commit
9264289813
4 changed files with 252 additions and 118 deletions
|
|
@ -3,10 +3,10 @@ import { sendOrderEmails, type EmailKind } from '$lib/server/email';
|
|||
import type { Actions, PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
// NOTE: there is no `created` field on orders (commerce collections were
|
||||
// imported without autodate fields) and PocketBase ids are random, so
|
||||
// '-id' is NOT chronological. See the polish report for the schema fix.
|
||||
const records = await locals.pb.collection('orders').getFullList({ sort: '-id' }).catch(() => []);
|
||||
// Newest first. `created` comes from the 1791244800 migration; orders made
|
||||
// before it have no date and sort last (PocketBase ids are random, so they
|
||||
// can't be ordered chronologically).
|
||||
const records = await locals.pb.collection('orders').getFullList({ sort: '-created,-id' }).catch(() => []);
|
||||
|
||||
// All lines in one request (previously one request per order).
|
||||
const lineRecords = records.length
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue