Repository navigation
feat(platform): restrict audit-log reads to org admins - #1852
Conversation
Close out the read-side authz gap from #1505: the public audit-log queries gated only on org membership, so any member could call them directly even though the UI and docs treat the log as admin-only. - Gate listAuditLogs, listAuditLogsPaginated and getActivitySummary behind an exported assertAuditLogReadAccess helper (admin/owner only). - Delete the unconsumed getResourceAuditTrail public query; the internal helper stays for the GDPR erasure flow. - Tighten the RLS matrix: auditLogs read drops to admin-only; developer/editor keep write (audit-row inserts), member drops to none (member audit rows already route through internal mutations). - Mirror the change in the client CASL ability matrix. - Fix the stale crons.ts comment claiming the integrity cron alerts on unsigned PII scrubs. - Document the in-app + Slack alert on a failed integrity check in en/de/fr. Writes are untouched: chain-link patches, retention deletes and the signed PII scrub keep working.
📝 WalkthroughWalkthroughThis PR hardens audit log access control by restricting read access to admin and owner roles across three enforcement layers. Query handlers now call Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/platform/convex/audit_logs/queries.ts`:
- Around line 18-21: The throw in assertAuditLogReadAccess currently uses a
hard-coded English message; change it to use a translation key or standardized
error code instead (e.g., throw new Error('ERR_AUDIT_LOG_READ_ACCESS') or use
the project's translation helper like t('errors.audit_logs.read_access')), so
update the throw in assertAuditLogReadAccess (and any tests that assert the
message) to reference the key/code rather than the English literal while keeping
the isAdmin(member.role) check intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d7c47462-a956-44ea-889e-ab813c528fe8
📒 Files selected for processing (10)
docs/de/platform/admin/governance/audit-logs.mddocs/en/platform/admin/governance/audit-logs.mddocs/fr/platform/admin/governance/audit-logs.mdservices/platform/convex/audit_logs/queries.tsservices/platform/convex/audit_logs/read_access.test.tsservices/platform/convex/crons.tsservices/platform/convex/lib/rls/helpers/access_control.test.tsservices/platform/convex/lib/rls/helpers/access_control.tsservices/platform/lib/permissions/ability.test.tsservices/platform/lib/permissions/ability.ts
| export function assertAuditLogReadAccess(member: OrganizationMember): void { | ||
| if (!isAdmin(member.role)) { | ||
| throw new Error('Only admins can read audit logs'); | ||
| } |
There was a problem hiding this comment.
Replace hard-coded English auth error with a translation key / error code.
Line 20 throws an English literal (Only admins can read audit logs). This violates the translation-layer rule and hard-codes locale into the API contract.
Suggested change
+export const AUDIT_LOG_READ_ACCESS_DENIED = 'auditLogs.readAccessDenied';
+
export function assertAuditLogReadAccess(member: OrganizationMember): void {
if (!isAdmin(member.role)) {
- throw new Error('Only admins can read audit logs');
+ throw new Error(AUDIT_LOG_READ_ACCESS_DENIED);
}
}As per coding guidelines: "Every user-facing string goes through the translation layer — never compare against an English literal in code, tests, stories, or comments."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export function assertAuditLogReadAccess(member: OrganizationMember): void { | |
| if (!isAdmin(member.role)) { | |
| throw new Error('Only admins can read audit logs'); | |
| } | |
| export const AUDIT_LOG_READ_ACCESS_DENIED = 'auditLogs.readAccessDenied'; | |
| export function assertAuditLogReadAccess(member: OrganizationMember): void { | |
| if (!isAdmin(member.role)) { | |
| throw new Error(AUDIT_LOG_READ_ACCESS_DENIED); | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@services/platform/convex/audit_logs/queries.ts` around lines 18 - 21, The
throw in assertAuditLogReadAccess currently uses a hard-coded English message;
change it to use a translation key or standardized error code instead (e.g.,
throw new Error('ERR_AUDIT_LOG_READ_ACCESS') or use the project's translation
helper like t('errors.audit_logs.read_access')), so update the throw in
assertAuditLogReadAccess (and any tests that assert the message) to reference
the key/code rather than the English literal while keeping the
isAdmin(member.role) check intact.
Source: Coding guidelines
What / why
Closes the last open gap from #1505 (audit-log hardening): the read side. The hash chain, nightly integrity cron + alerting, append-only test, retention, and admin-gated export already shipped (#1805, #1820) — but the four public queries in
convex/audit_logs/queries.tsgated only on org membership, so any member/editor/developer could read the full org audit trail by calling the API directly, contradicting the admin-only UI gate (orgSettings) and the docs ("Admins and Owners read this").listAuditLogs,listAuditLogsPaginated,getActivitySummarynow throw for non-admin/owner roles via an exportedassertAuditLogReadAccesshelper (same pattern asverifyIntegrityand governancelistTrashedRows), unit-tested across all roles inread_access.test.ts.getResourceAuditTrail(public query) — zero consumers anywhere in the repo. Thehelpers.tsfunction of the same name stays; the GDPR erasure flow uses it internally.access_control.ts, defense-in-depth):auditLogsread is now admin-only. Developer/editor drop toWRITE_ONLY(write must stay — the RLSinsertrule authorizes audit-row inserts); member drops toNONE(member audit rows already bypass RLS viainternal_mutations.createAuditLog, seeprompts/mutations.ts). Themodifyrule is untouched so the chain-linkchainSuccessorpatch keeps working.lib/permissions/ability.ts):cannot('read', 'auditLogs')for developer and member, removed from the editor read-only list. Consistency-only — no UI consumer checks this subject today.append_only.test.ts).crons.tscomment claiming the integrity cron alerts on unsigned PII scrubs (it deliberately does not).docs/{en,de,fr}/platform/admin/governance/audit-logs.mddocumenting that a failed integrity check also raises a critical in-app notification to admins and fans out to Slack.Decision-gate recommendations baked in
orgSettingsUI gate (not admin+developer). The scoped skills change-history endpoint stays admin-OR-developer, unchanged.getResourceAuditTraildeleted rather than gated — it had no consumer.Verification
Performed:
bun run checkat repo root — all 40 tasks green (366 platform test files / 71,917 tests).vitest run convex/audit_logs convex/lib/rls/helpers lib/permissions— 9 files, 84 tests pass.bun run --filter @tale/docs lintandbun run --filter @tale/docs test— locale parity green.Manual verification required
memberoreditorand callapi.audit_logs.queries.listAuditLogsPaginatedfrom the browser console → expect "Only admins can read audit logs"; as admin → rows return; the audit-logs settings page is unaffected (already behind the admin-only governance route).Pre-PR checklist
bun run check(format, lint, typecheck, all tests).h-[…]on skeletons — N/A (no UI rendering change).services/platform/messages/{en,de,fr}.json— N/A (no new user-facing strings; the gate error is an API-level error, consistent with the existingverifyIntegritygate)./docs/{en,de,fr}/for every user-visible change (audit-logs page, alerting sentence, all three locales).bun run --filter @tale/docs lintandbun run --filter @tale/docs test.README.md/README.de.md/README.fr.md— N/A.Part of #1803. Closes the read-side authz items of #1505 (requirement 4 and the RLS confirmation); together with the already-merged #1805/#1820 this completes the issue's acceptance criteria — Part of #1505.
Summary by CodeRabbit
New Features
Documentation