Skip to content

fix(workspace-forking): scope fork-sync document copies to the source workspace - #10321

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/fork-sync-kb-doc-tenant-scope
Nov 22, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/fork-sync-kb-doc-tenant-scope

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fork sync's mapped-KB document copy (planForkMappedKbDocumentCopies) selected candidate documents by id only, so a caller could pass another workspace's document id (through dependentValues, or a source workflow reference) together with a mapping from that workspace's KB to a KB they own, and the sync copied the document row, blob and chunks into their KB
  • Scope the candidate query to KBs in the source workspace — the only source read in the copy path missing that predicate (tables, KBs, skills, tools, MCP servers and files already carry it)
  • Apply the same scope to the post-commit re-read in copyForkResourceContent, so a content payload queued before this deploy cannot fill a foreign document
  • Mapping sourceId validation and dependentValues filtering are left as-is: the editor intentionally accepts source ids absent from the source workspace (sourceDeleted), and source workflow state can carry a foreign id regardless, so the read boundary is the fix

Type of Change

  • Bug fix (security)

Testing

  • Two new real-Postgres tests in lib/workspaces/__integration__/fork-sync.integration.ts: an end-to-end push sync (no preview admission) with a foreign KB mapping + foreign document id in dependentValues, and a post-commit fill handed a foreign source document
  • Both red on pre-fix staging; each goes red again when only its own guard is reverted; full file 23/23 green with the fix
  • copy-resources.test.ts + copy-unmapped.test.ts passing, biome clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 22, 2026 10:51pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; both document-copy reads now enforce the source workspace.

Summary

This PR limits mapped-knowledge-base document copies to the source workspace.

  • Fork sync's mapped document copies stay within the source workspace.

No actionable issues were found. Tests were inspected but not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Workflow references and dependent values] --> B{Document belongs to source workspace?}
  B -->|No| C[Skip document and mapping]
  B -->|Yes| D[Create placeholder and queue copy]
  D --> E{Source document still belongs to source workspace?}
  E -->|No| F[Report failed document copy]
  E -->|Yes| G[Copy blob and chunks]
  G --> H[Activate target document]
Loading

Reviews (1) · Last reviewed commit: "fix(workspace-forking): scope fork-sync ..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 1f76338 into staging Nov 22, 2026
84 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/fork-sync-kb-doc-tenant-scope branch November 23, 2026 00:04

This branch was previously deployed

1 inactive deployment
Preview — 1e43e105 Deployed Nov 22, 2026 by vercel[bot]
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