fix(mothership): scope mothership block tool permissions to the executing user#4843
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview That closes a gap on the headless / Mothership block lifecycle path: the execute route could forward A regression test in Reviewed by Cursor Bugbot for commit 10b0cee. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes a permission-scoping gap in the Mothership block execution path:
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted two-line addition that mirrors an already-established pattern in the same function. The fix reads a server-generated value (already validated against the DB in the execute route) from the request payload, using the same defensive type-check and falsy-guard idiom used for No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Executor as Workflow Executor
participant Route as /api/mothership/execute
participant DB as Database
participant Headless as runHeadlessCopilotLifecycle
participant Lifecycle as runCopilotLifecycle
participant BuildCtx as buildExecutionContext
participant Tools as Tool Router
Executor->>Route: POST (internal JWT auth)
Route->>DB: getUserEntityPermissions(userId, workspaceId)
DB-->>Route: "userPermission (read|write|admin|null)"
Note over Route: Build requestPayload with userPermission
Route->>Headless: runHeadlessCopilotLifecycle(requestPayload, options)
Headless->>Lifecycle: runCopilotLifecycle(requestPayload, options)
Lifecycle->>BuildCtx: buildExecutionContext(requestPayload, params)
Note over BuildCtx: NEW: reads userPermission from requestPayload
BuildCtx-->>Lifecycle: execContext with userPermission set
Lifecycle->>Tools: executeToolAndReport(execContext)
Note over Tools: isWritePermission(execContext.userPermission) now correctly enforced
Reviews (1): Last reviewed commit: "fix(mothership): scope mothership block ..." | Re-trigger Greptile |
Summary
buildExecutionContextnow readsuserPermissionfrom the request payload and sets it on the execution context, so Mothership block runs enforce the executing user's workspace permissionsuserPermission, but the headless/block lifecycle path dropped it — tools ran withuserPermission: undefined(writes either hard-denied or silently unenforced depending on the tool)userPermissionpropagates into the generated execution contextType of Change
Testing
Tested manually.
run.test.tspasses (3/3); verified the new test fails without the fix.bun run lintclean;bun run check:api-validation:strictpassed.Checklist