fix(security): enforce note edit access on PDF derive-page - #1063
Merged
Conversation
POST /api/sources/pdf/.../derive-page accepted an arbitrary noteId without checking membership, allowing authenticated users to inject pages into notes they cannot edit. Mirror POST /api/pages permission checks when noteId is set. Also correct zedi_remove_page_from_note MCP description: after issue #823 the endpoint soft-deletes the page; there is no unlink-only mode. Co-authored-by: akimasa.sugai <akimasa.sugai@saedgewell.com>
otomatty
force-pushed
the
cursor/critical-bug-investigation-6113
branch
from
June 13, 2026 05:33
7dfb273 to
b6adebc
Compare
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.
Summary
Critical bug investigation (triggered by PR #1062) found a permission bypass in the PDF derive-page API. This PR adds the missing note edit check and corrects a misleading MCP tool description that could cause accidental page deletion.
Bug and impact
PDF derive-page authorization bypass
POST /api/sources/pdf/:sourceId/highlights/:highlightId/derive-pageaccepted an optionalnoteIdin the request body but never verified that the caller could edit that note. Any authenticated user who owned a PDF highlight could create a page inside another user's note by supplying the victim'snoteId.Impact: Cross-note content injection — pages appear in notes the attacker does not belong to.
Trigger scenario:
POST .../derive-pagewith{ "noteId": "<victim-note-uuid>", "title": "injected" }.owner_id = attackerbutnote_id = victim note.Root cause
POST /api/pagesgainedgetNoteRole+canEditchecks when an explicitnote_idis provided, but the PDF derive-page route (added in #858) was never updated. A comment deferred the check ("将来 import で共有してもよい").Fix
noteIdis explicitly provided on derive-page, require edit access viagetNoteRole+canEdit(same pattern asPOST /api/pages).zedi_remove_page_from_noteMCP tool description: after issue 既存個人ページをデフォルトノートに移行し note_pages を廃止する (default note PR 1b) #823, the API soft-deletes the page; there is no unlink-only mode. Prevents MCP agents from treating the tool as a safe unlink.Validation
server/api/src/__tests__/routes/pdfSources.test.ts— asserts 403 whennoteIdpoints to a foreign private note.bunx vitest run src/__tests__/routes/pdfSources.test.tspasses.Other findings (not fixed in this PR)
state.messagesbut Brief answers live instate.brief— research may ignore user Brief input (quality degradation, not data loss).noteId: nullrows: hidden until sync succeeds (temporary UX gap after refactor(front+server): 個人ページ(noteId === null)概念を根絶し Page.noteId を non-null 化 (#1020) #1023 upgrade).PR #1062 itself (actions/checkout 6.0.2 → 6.0.3) contains no application logic changes.