Skip to content

Deleting a doc collection relocates pages the deleter cannot write #245

Closed

Description

@imshashank

Found during review of #241 by CodeRabbit. Pre-existing, not introduced there.

What happens

deleteDocCollection checks the workspace level doc:write capability, then emptyCollection updates every document whose collection_id matches, with no per document authorization:

packages/core/src/content/doc-service.ts  emptyCollection / deleteDocCollection

Elsewhere a write goes through assertDocWritable, which honours doc_access and the document's visibility. This path does not. So a member who may manage documents can relocate a document they are not allowed to edit by deleting the collection it sits in.

What it does and does not do

The decision to make

The fix is not just adding a check, it is choosing what should happen when a collection holds a document the deleter cannot write:

  1. refuse the whole delete and name the documents in the way, or
  2. delete the collection, relocate only the documents the caller may write, and leave the rest where they are, which leaves rows pointing at a collection that no longer exists unless the column is nulled anyway, or
  3. restrict collection deletion to a role that can modify every document in the organisation.

Option 1 is the most predictable and the easiest to explain, but it makes a delete fail for a reason the person cannot see or fix. Worth deciding deliberately rather than picking one inside an outage fix.

Whichever is chosen needs a test that a member without write access to a document cannot move it by deleting its collection.

Activity

  1. added
    bug
    security
    needs design
    p1 high
    area: policy
    area: docs-feature
    size: medium
    points: 3
    on Aug 8, 2026
  2. imshashank commented on Aug 15, 2026

    @imshashank
    ContributorAuthor

    Re-verified on 3ba32cb. Still reproduces exactly as described, unchanged since filing.

    deleteDocCollection in packages/core/src/content/doc-service.ts still checks only the workspace-level capability:

    export async function deleteDocCollection(
      principal: Principal,
      collectionId: string,
      reassignToId: string | null = null,
    ): Promise<SyncAction[]> {
      assertCan(principal, 'doc:write');

    and emptyCollection still performs an unfiltered bulk update over every document in the collection, with no assertDocWritable and no docReadFilter:

    .update(schema.doc)
    .set({ collectionId: reassignToId, updatedAt: new Date(), syncId })
    .where(and(eq(schema.doc.organizationId, organizationId), eq(schema.doc.collectionId, collectionId)))

    Adding triage labels, since this arrived with only bug. Marked security and p1 high on the reasoning already in the description: it is a write that bypasses per-document authorization, which is a boundary the rest of the docs service enforces. The impact is genuinely limited, as the issue is careful to say, since it relocates rather than reads or deletes, so this is not urgent in the way a read leak would be.

    Marked needs design because the fix is still the choice between the three options listed here rather than a check to drop in, and that choice has not been made. Option 1, refuse the delete and name the documents in the way, is the most defensible and is the one I would pick: it is the only one that leaves no surprising state, and the error message doubles as an explanation of why. Option 2 leaves rows pointing at a deleted collection, and option 3 changes who can manage collections at all, which is a larger product change than this bug warrants.

    Worth confirming with a test either way. packages/core/tests/content/doc-service.test.ts already builds principals with differing document access, so the fixtures for this exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docs-featurearea: policybugneeds designp1 highpoints: 3securitysize: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions