Skip to content

fix(sdk): verify agent ownership in eval routes - #3

Open
manpreet171 wants to merge 1 commit into
jayasukuv11-beep:mainfrom
manpreet171:fix/evals-ownership-checks
Open

fix(sdk): verify agent ownership in eval routes#3
manpreet171 wants to merge 1 commit into
jayasukuv11-beep:mainfrom
manpreet171:fix/evals-ownership-checks

Conversation

@manpreet171

Copy link
Copy Markdown

Problem

validateConnectKey() returns a service role Supabase client, which bypasses RLS. Routes that accept an agent_id from the request therefore have to check ownership themselves — traces, command, checkpoint and execution all do this.

The four evals routes don't. They authenticate the caller and then query using ids taken straight from the request body:

Route Effect with any valid connect key
GET /api/sdk/evals/regression read another user's regressions via agent_id
PATCH /api/sdk/evals/regression acknowledge another user's regression via regression_id
POST /api/sdk/evals/regression read their eval results and insert rows
POST /api/sdk/evals/results write results / create eval sets under their agent
POST /api/sdk/evals/from-trace read their checkpoints, tool executions and reasoning steps via task_id

The GET and PATCH cases need no plan gate, so a free account is enough.

Fix

Added an ownsAgent() helper in lib/sdk-auth.ts and used it in the routes that were missing the check. Where a route accepts an eval_set_id, regression_id or task_id, that id is resolved back to its agent (or user) first, so a caller can't pair their own agent_id with someone else's record.

Responses follow the existing convention: 403 with Unauthorized agent access.

Tests

tests/evals_security.test.ts mirrors the structure of tests/traces_security.test.ts. 6 of the 8 new tests fail on main and pass with this change.

Full suite: 174 passed, and tsc --noEmit is clean.

The eval routes accepted agent_id, eval_set_id and regression_id straight
from the request and queried with the service role client, which bypasses
RLS. Any valid connect key could therefore read or write eval data
belonging to another user.

Adds an ownsAgent() helper next to the other sdk-auth logic and uses it in
the routes that were missing the check, matching what traces, command,
checkpoint and execution already do.
@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

@manpreet171 is attempting to deploy a commit to the tharagesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

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