Skip to content

fix(comments): author-only delete and validate target ids#4

Merged
feRpicoral merged 2 commits into
mainfrom
fix/comment-authorization
May 27, 2026
Merged

fix(comments): author-only delete and validate target ids#4
feRpicoral merged 2 commits into
mainfrom
fix/comment-authorization

Conversation

@feRpicoral
Copy link
Copy Markdown
Owner

Closes two Codex findings on the comments routes.

P1 — delete authorization was UI-only. Any org member who knew a comment id could DELETE /api/comments/[id]. The kebab menu already hides Delete for non-authors; the server now enforces the same rule (403 if authorUserId !== session.userId). Resolve/reopen remains org-wide, matching the UI which surfaces it to everyone.

P2 — comment creation didn't validate targets. POST /api/comments wrote targetId blindly because the column is polymorphic and carries no FK. Now:

  • MESSAGE targets must resolve to a Message in the caller's org (via auto-scoped findUnique).
  • DOCUMENT_REGION targets must resolve to a Document in the caller's org, and the location's kind must match the document's format (pdf for PDFs, html for DOCX/HTML/MD) so the viewer never gets a region it can't render.

Verified with yarn test (52 unit) and yarn lint.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cite Ready Ready Preview, Comment May 26, 2026 9:23pm

@feRpicoral feRpicoral force-pushed the fix/comment-authorization branch from 7953dd2 to db457fc Compare May 26, 2026 21:05
@feRpicoral feRpicoral marked this pull request as ready for review May 26, 2026 21:20
@feRpicoral feRpicoral merged commit 82f5e3e into main May 27, 2026
4 checks passed
@feRpicoral feRpicoral deleted the fix/comment-authorization branch May 27, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant