fix(knowledge): stop listing workspace knowledge bases on stale creator identity - #6454
Conversation
…or identity GET /api/knowledge without a workspaceId ORed on knowledge_base.user_id with no permission check, so a user removed from a workspace kept seeing metadata for every KB they created there. Scope the creator fallback to legacy KBs with no workspaceId, matching the workspace-filtered branch and the detail path.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The listing predicate is tightened so workspace KBs require current workspace membership ( Tests assert the creator disjunct always includes the Reviewed by Cursor Bugbot for commit 88f9774. Configure here. |
Greptile SummaryThe PR narrows creator-based knowledge-base listing access to legacy records without a workspace, preventing former workspace members from retaining metadata access through stale creator identity.
Confidence Score: 5/5The PR appears safe to merge because the authorization predicate is correctly narrowed and both filtered and unfiltered paths are covered by regression tests. The shared predicate preserves current workspace-member access while limiting creator fallback to non-workspace legacy records, and the optional Drizzle condition and SQL mock behavior are compatible with current callers.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/knowledge/service.ts | Consolidates listing authorization while restricting creator fallback to legacy knowledge bases whose workspace ID is null; no changed-code defect was identified. |
| apps/sim/lib/knowledge/service.test.ts | Adds structural regression tests confirming that both listing modes guard creator access with a null workspace ID. |
| packages/testing/src/mocks/database.mock.ts | Adds sufficient sql.mapWith support for current mocked query projections without affecting existing mock behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Request["List knowledge bases"] --> Scope{"Workspace filter supplied?"}
Scope -->|Yes| Match["Require matching workspace ID"]
Scope -->|No| Membership["Consider all current workspace memberships"]
Match --> Membership
Membership --> Current{"Current permission row and workspace active?"}
Current -->|Yes| Include["Include workspace knowledge base"]
Current -->|No| Legacy{"Creator and workspaceId is null?"}
Legacy -->|Yes| IncludeLegacy["Include legacy knowledge base"]
Legacy -->|No| Exclude["Exclude knowledge base"]
Reviews (1): Last reviewed commit: "fix(knowledge): stop listing workspace k..." | Re-trigger Greptile
Summary
GET /api/knowledgewithout aworkspaceIdORed onknowledge_base.user_idwith no permission check and noworkspaceId IS NULLguard, so a user removed from a workspace kept seeing metadata (name, description,docCount,tokenCount, connectors) for every KB they created there — indefinitely, including KBs in archived workspaces underscope=allworkspaceId, matching what the workspace-filtered branch andresolveKnowledgeBaseAccessalready enforceor(...)shapes into one so both call paths share the same two authorization predicatesmapWithto the shared drizzlesqltest mock so this query is testable at allType of Change
Testing
bun run type-check,bun run lint, and 2054 tests acrosslib/knowledge,app/api/knowledge,app/api/v1,lib/copilot,lib/tablepass. New tests assert the creator disjunct carries theworkspaceId IS NULLguard on both branches — verified they go red against the pre-fix predicate.No client relies on the unfiltered branch: every in-app caller (
useKnowledgeBasesList,/api/v1/knowledge, copilot VFS) passes aworkspaceId.Checklist