fix(knowledge): enforce trusted workspace scope - #6452
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Connectors, documents, chunks, and tag-definitions routes no longer inline Drizzle queries, Document and chunk handlers keep secret provenance behavior through Route-level Vitest suites for these handlers are removed from Reviewed by Cursor Bugbot for commit c0d251f. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThe PR centralizes Knowledge authorization around canonical resource resolution and trusted delegated execution scope.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/knowledge/application/authorization.ts | Defines shared Knowledge delegation policy and canonical workspace authorization behavior. |
| apps/sim/lib/knowledge/application/contexts.ts | Resolves knowledge bases and child resources to canonical workspace contexts before authorization. |
| apps/sim/lib/knowledge/application/chunks.ts | Moves chunk operations behind application authorization while retaining rejection of unavailable secret provenance. |
| apps/sim/lib/api/server/routes/internal-json-route.ts | Introduces the declarative internal JSON route lifecycle used by migrated Knowledge endpoints. |
| apps/sim/lib/api/server/routes/v2-body-lifecycle-route.ts | Encapsulates v2 authentication, admission, body parsing, and application-use-case execution. |
| apps/sim/lib/copilot/tool-executor/executor.ts | Supplies trusted user, workflow, workspace, and execution context when Copilot dispatches application tools. |
| apps/sim/tools/index.ts | Generates delegated executor authentication for Knowledge ToolConfig HTTP requests. |
| apps/sim/lib/copilot/application/execute-knowledge-use-case.ts | Adapts Copilot Knowledge operations to shared application use cases and trusted execution scope. |
| apps/sim/lib/knowledge/application/add-workspace-files.ts | Composes canonical authorization, usage admission, file registration, processing, audit, and effects into one bounded command. |
| apps/sim/lib/knowledge/application/documents.ts | Centralizes authorized document operations, including bounded bulk behavior and partial outcomes. |
| apps/sim/lib/knowledge/application/connectors.ts | Moves connector reads, updates, deletion, document exclusion, and synchronization behind canonical authorization. |
| apps/sim/lib/knowledge/application/search.ts | Performs Knowledge search as one authorized operation and returns canonical presentation metadata. |
Sequence Diagram
sequenceDiagram
participant Caller as Session/API key/Copilot
participant Route as Knowledge route adapter
participant Context as Canonical context resolver
participant Authz as Workspace authorization
participant UseCase as Knowledge application use case
participant Store as DB/Object storage/Vector store
Caller->>Route: Knowledge request
Route->>Route: Authenticate trusted principal
Route->>UseCase: Validated input and principal
UseCase->>Context: Resolve requested resource
Context-->>UseCase: Canonical workspace and resource
UseCase->>Authz: Authorize principal against canonical scope
Authz-->>UseCase: Current permission decision
UseCase->>Store: Read or mutate authorized resource
Store-->>UseCase: Result
UseCase-->>Route: Application outcome
Route-->>Caller: Compatible response envelope
Reviews (6): Last reviewed commit: "fix(knowledge): finalize partial batch e..." | Re-trigger Greptile
5c45991 to
6c8a34e
Compare
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6c8a34e. Configure here.
6c8a34e to
79c5879
Compare
|
@cursor review |
|
@cursor review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
1 issue from previous review remains unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0af5acf. Configure here.

Summary
knowledge_baseCopilot branch through the shared Copilot application adapteradd_file, bulk knowledge-base delete, and bulk document delete as three fixed bounded application commands with no nested authorized use cases or generic multi-operation executordefineInternalJsonRoute, including explicit session-only operations for legacy personal knowledge basesComposition behavior
addWorkspaceFilesToKnowledgeBaseowns canonical KB/file resolution, per-resource current authorization, provenance checks, presigned storage preparation, one bounded usage admission, sequential best-effort registration/processing, authoritative audit, and success effectsbulkDeleteKnowledgeBasesandbulkDeleteKnowledgeDocumentseach have a distinct semantic operation, a 100-item sequential best-effort cost policy, per-resource canonical authorization, explicit partial outcomes, audit, effects, and cancellation statesearchKnowledgeremains one semantic query operation with an explicit post-parse cost policy and now returns canonical KB presentation metadata, removing the redundant pre-search readTrusted identity
_contextcannot supply itCopilot tool inventory
create,get, andupdatenow enter exclusively throughexecuteCopilotKnowledgeUseCasequeryuses oneknowledge.searchcommand and its canonical presentation metadataadd_fileuses one boundedknowledge.documents.add_workspace_filescommanddeleteuses one boundedknowledge.bulk_deletecommanddelete_documentuses one boundedknowledge.documents.bulk_deletecommandupdate_documentlist_tags,create_tag,update_tag,delete_tag,get_tag_usageadd_connector,update_connector,delete_connector,sync_connectorInternal Knowledge route inventory
/api/knowledgeand/api/knowledge/[id]/api/knowledge/[id]/restore/api/knowledge/search/api/knowledge/[id]/documentsand/api/knowledge/[id]/documents/[documentId]/api/knowledge/[id]/documents/[documentId]/chunksand/api/knowledge/[id]/documents/[documentId]/chunks/[chunkId]/api/knowledge/[id]/documents/[documentId]/tag-definitions/api/knowledge/[id]/documents/upsert/api/knowledge/[id]/documents/uploads,/api/knowledge/[id]/documents/uploads/[uploadId],/parts, and/complete/api/knowledge/[id]/tag-definitions,/api/knowledge/[id]/tag-definitions/[tagId],/api/knowledge/[id]/tag-usage, and/api/knowledge/[id]/next-available-slot/api/knowledge/[id]/connectors,/api/knowledge/[id]/connectors/[connectorId],/documents, and/sync/api/knowledge/connectors/syncis a cron-authenticated capped scheduler/recovery job, not an ordinary caller resource operationv2 inventory
Compatibility and safety
/api/knowledgestill accepts omittedworkspaceIdfor personal knowledge bases andscope=active|archived|allPersonalApiKeysDisabledErrorremains 403; shared v2 concealment converts only resource authorization failures to 404bun.lockchangeType of Change
Testing
bun run check:api-validation:strictgit diff --checkChecklist