Repository navigation
Enforce task run ownership across REST and MCP - #1035
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
1 issue found across 12 files
Confidence score: 4/5
- The matcher in
registerGetTaskRunStatusTool.test.tscan pass even if the response includesTrigger API error, so a provider exception could leak without the test catching it. Assert the exact redacted response.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/mcp/tools/tasks/__tests__/registerGetTaskRunStatusTool.test.ts">
<violation number="1" location="lib/mcp/tools/tasks/__tests__/registerGetTaskRunStatusTool.test.ts:225">
P2: This matcher still passes if the response appends `Trigger API error`, so it does not guard against leaking the provider exception. Assert the exact redacted response.
(Based on your team's feedback about redacting internal error details.)</violation>
</file>
Architecture diagram
sequenceDiagram
participant Client as External Client (REST / MCP)
participant API as API Route Layer
participant Auth as Auth Context
participant Query as Query Validator
participant Ownership as canReadTaskRun
participant Trigger as Trigger SDK
participant DB as Supabase Scheduled Actions
participant McpServer as MCP Server
Note over Client,McpServer: Task Run Ownership Enforcement Flow
rect rgb(240, 240, 240)
Note over Client,McpServer: REST Path
Client->>API: GET /api/tasks/runs?runId=xxx&account_id=xxx
API->>Auth: Validate auth context
Auth-->>API: accountId, authToken
API->>Query: validateGetTaskRunQuery(request)
Query->>Query: Parse runId, limit, account_id
alt runId provided
Query->>Query: Resolve target accountId
alt account_id override present
Query->>Query: Validate override permissions
alt Unauthorized override
Query-->>API: 403 Forbidden
API-->>Client: 403 error response
else Authorized override
Query-->>API: { mode: retrieve, runId, accountId }
end
else No override
Query-->>API: { mode: retrieve, runId, accountId }
end
API->>Trigger: retrieveTaskRun(runId)
Trigger->>Trigger: Call Trigger.dev runs.retrieve
alt Provider 404
Trigger-->>API: null (normalized)
API-->>Client: 404 "Task run not found"
else Provider error
Trigger-->>API: Throws error
API-->>Client: 500 "Failed to retrieve task runs"
else Run found
Trigger-->>API: Task run object
API->>Ownership: canReadTaskRun(run, accountId)
Ownership->>Ownership: Parse payload fields
alt Payload owners present
Ownership->>Ownership: Verify all owners match
alt Contradictory owners
Ownership-->>API: false
API-->>Client: 404 "Task run not found"
else Owners match
Ownership-->>API: true
end
else No payload owner, externalId present
Ownership->>DB: selectScheduledActions(id, account_id)
DB-->>Ownership: Scheduled task record
alt Task found and owner matches
Ownership-->>API: true
else Task not found
Ownership-->>API: false
API-->>Client: 404 "Task run not found"
end
else Legacy tags only
Ownership->>Ownership: Filter account: tags
alt Single matching tag
Ownership-->>API: true
else Multiple/ambiguous tags
Ownership-->>API: false
API-->>Client: 404 "Task run not found"
end
end
alt Ownership verified
API-->>Client: 200 with run details
end
end
else No runId
API-->>Client: 200 with recent runs list
end
end
rect rgb(235, 245, 255)
Note over Client,McpServer: MCP Path (API-key tool)
Client->>McpServer: Call get_task_run_status(runId)
McpServer->>Auth: resolveAccountId(apiKey)
Auth-->>McpServer: accountId
McpServer->>Trigger: retrieveTaskRun(runId)
Trigger-->>McpServer: Task run object or null
alt Run not found
McpServer-->>Client: "Task run not found" error
else Run found
McpServer->>Ownership: canReadTaskRun(run, accountId)
Ownership-->>McpServer: true/false
alt Ownership verified
McpServer-->>Client: Success with run data
else Not owned
McpServer-->>Client: "Task run not found" error
end
end
end
rect rgb(245, 245, 250)
Note over Client,McpServer: OAuth Path (unchanged)
Client->>McpServer: Call get_task_run_status(runId)
McpServer->>Trigger: retrieveTaskRun(runId)
Trigger-->>McpServer: Task run object
McpServer->>Ownership: canReadTaskRun(run, accountId)
Ownership-->>McpServer: true/false
alt Ownership verified
McpServer-->>Client: Status-only response
else Not owned
McpServer-->>Client: "Task run not found" error
end
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| { | ||
| type: "text", | ||
| text: expect.stringContaining("Trigger API error"), | ||
| text: expect.stringContaining("Failed to retrieve task run"), |
There was a problem hiding this comment.
P2: This matcher still passes if the response appends Trigger API error, so it does not guard against leaking the provider exception. Assert the exact redacted response.
(Based on your team's feedback about redacting internal error details.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/tasks/__tests__/registerGetTaskRunStatusTool.test.ts, line 225:
<comment>This matcher still passes if the response appends `Trigger API error`, so it does not guard against leaking the provider exception. Assert the exact redacted response.
(Based on your team's feedback about redacting internal error details.) </comment>
<file context>
@@ -202,7 +222,7 @@ describe("registerGetTaskRunStatusTool", () => {
{
type: "text",
- text: expect.stringContaining("Trigger API error"),
+ text: expect.stringContaining("Failed to retrieve task run"),
},
],
</file context>
| text: expect.stringContaining("Failed to retrieve task run"), | |
| text: '{"success":false,"message":"Failed to retrieve task run"}', |
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
A signed-in caller could retrieve another account's Trigger run by ID through REST or the API-key MCP tool. Both now use the same ownership check as OAuth before returning run data. Authorized account overrides are validated in retrieve mode as well as list mode; inaccessible and unattributed runs return not found.
The shared check uses server-returned payload ownership, a persisted scheduled-task owner, or unambiguous worker-issued legacy account tags. Contradictory payload owners are denied. OAuth keeps its restricted status-only response. Provider 404s are normalized and other provider error details are withheld from client responses.
Validation: 170 tests pass across task handlers, MCP task tools, OAuth adapters/catalog/routing and Trigger retrieval; repository lint and extension build pass. Full typecheck still fails on existing issues; comparison against untouched main with the same dependencies found no new error signatures. No live customer runs were read or changed.
Production impact: own runs remain readable. Foreign or unattributed legacy run links are withheld; no database migration or broad legacy bypass is introduced. Repository credential containment and browser execution credential binding are separate follow-up P0 work.
Summary by cubic
Stops signed-in callers from retrieving another account's Trigger run by ID through the REST endpoint or the API-key MCP tool. REST and MCP now share the same ownership check OAuth already used, and foreign or unattributed runs return not found instead of run data.
schedule.externalId), or unambiguous worker-issued legacy account tags; contradictory owners and schedule IDs are denied.account_idoverrides are now validated in retrieve mode as well as list mode.Written for commit 99ff21d. Summary will update on new commits.