Files
KomediruzeckiandGitHub c6b417a7c0 fix(worker): custom-report IDOR, fail-closed CORS, verify Google iss/exp (#238)
- reports.ts: custom reports lived in a per-isolate in-memory Map keyed by a
  Date.now() id with no ownership check, so any authenticated user could
  read/update/delete another user's report id (an IDOR, conditional on a
  shared warm isolate). Persist them in D1 (new custom_reports table,
  migration 0011), scoped by user_id on every read and write. /save and
  /saved are now D1-backed and user-scoped too (they were an ephemeral Map
  write and an empty stub).
- index.ts: CORS failed OPEN to `*` + credentials when CORS_ORIGIN is unset;
  fail closed instead.
- auth.ts: verifyGoogleIdToken checked only `aud`; also pin `iss`
  (accounts.google.com) and `exp` as defense in depth.

Adds a workerd + D1 test (reports-custom.test.ts): a user cannot read/update/
delete another user's report (404), and /saved lists only the caller's
reports. pnpm -C worker test -> 17 passing.
2026-07-01 20:48:09 +02:00

14 lines
699 B
SQL

-- Custom reports were kept in a per-isolate in-memory Map keyed by a Date.now() id with no
-- ownership check, so any authenticated user could read/update/delete another user's report id
-- (an IDOR, conditional on a shared warm isolate). Persist them in D1, scoped by user_id.
CREATE TABLE IF NOT EXISTS custom_reports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL REFERENCES users(id),
name TEXT NOT NULL,
type TEXT NOT NULL DEFAULT 'custom',
config TEXT NOT NULL DEFAULT '{}',
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_custom_reports_user ON custom_reports(user_id);