fix(reports): owner-gate the saved-report schedule routes (#2980) - #6683
Merged
Conversation
`unscheduleReport` and `listSchedules` took the caller context as `_context` and never consulted it, querying under the RLS-bypassing system context. Any authenticated caller could delete another owner's report schedule (a cross-owner destructive write) or list another owner's schedules (leaking recipients + cron) by supplying an id, even though the sibling read/run/delete routes are all owner-isolated. Both now resolve the schedule's parent report and require the caller to own it, mirroring the sibling routes: - unscheduleReport: loads the schedule, then its report, and deletes only when canAccessReport holds; a cross-owner attempt throws REPORT_NOT_FOUND (mapped to 404 in the REST layer — deny-as-404, anti-enumeration), while a genuinely-absent schedule stays idempotent. Create was already gated via getReport, so only the delete/list doors were open. - listSchedules: returns an empty list to any non-system caller who cannot access the report it is scoped to — the same non-leaking posture as listReports. The scheduler's system context still sees every schedule. Tests: 5 new owner-gate cases in report-service.test.ts (cross-owner delete denied + schedule survives, unknown-id idempotent, cross-owner list empty, system context still lists). No authoring-surface or metadata change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L8aEBrJVxRnA5XVRkeVft9
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 12 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes the D1 finding from the platform-checklist sweep (#6557
FOLLOW-UPS.md§1, tracked in #6681): the two saved-report schedule routes were not owner-isolated, while every sibling report route is.packages/plugins/plugin-reports/src/report-service.ts—unscheduleReportandlistSchedulestook the callercontextas_contextand never consulted it, querying under the RLS-bypassing system context. Any authenticated caller could therefore:simply by supplying an id.
canAccessReportalready gatesgetReport/deleteReport/run/saveReport/listReports(andscheduleReportviagetReport), so only the delete/list schedule doors were open.Fix
Both methods now resolve the schedule's parent report and require the caller to own it, mirroring the sibling routes:
unscheduleReportloads the schedule, then its report, and deletes only whencanAccessReportholds. A cross-owner attempt throwsREPORT_NOT_FOUND(deny-as-404, anti-enumeration — never a cross-owner 2xx); a genuinely-absent schedule stays idempotent, matchingdeleteReport.listSchedulesreturns an empty list to any non-system caller who cannot access the report it is scoped to — the same non-leaking posture aslistReports. The scheduler's system context still sees every schedule.packages/rest/src/rest-server.ts— the DELETE-schedule route now runs the section's existinghandleValidationhelper in its catch, soREPORT_NOT_FOUNDsurfaces as404instead of500(same mapping the POST-schedule route already uses).Includes a changeset (
@objectstack/plugin-reports+@objectstack/rest, patch). No authoring-surface or metadata change; existing owner-path behavior is unchanged.Tests
report-service.test.tsgains 5 owner-gate cases — cross-owner delete denied and schedule survives, unknown-id delete idempotent, cross-owner list empty, system-context list still sees schedules.pnpm --filter @objectstack/plugin-reports test→ 42 passed.Note: the full
@objectstack/resttest suite (rest.test.ts) could not run in the authoring container because@objectstack/spec's build is independently red on this branch (an ADR-0087 governance guard: 62 schemas left the published set with no registered removal — unrelated to this diff). The REST change is a one-line reuse of a helper already invoked twice in the same function.Follow-ups (tracked in #6681, not in this PR)
dashboards.saved-report-ownershipknown-gap probe from expected-fail to a positive deny-as-404 assertion.🤖 Generated with Claude Code
https://claude.ai/code/session_01L8aEBrJVxRnA5XVRkeVft9
Generated by Claude Code