Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5057,7 +5057,7 @@ function canSessionAccessPath(env: Env, identity: Extract<AuthIdentity, { kind:
if (isRepoCheckBeforeStartPath(path)) return true;
if (isRepoValidateLinkedIssuePath(path)) return true;
if (isRepoAgentAuditFeedPath(path)) return true; // route's requireRepoMaintainer enforces per-repo authority (contributors → 403)
if (isRepoAgentPendingActionsPath(path)) return true; // list: requireRepoMaintainer; decide: requireRepoWriteAccess
if (isRepoAgentPendingActionsPath(path)) return true; // list-only: requireRepoMaintainer; decision POSTs require server tokens
if (isRepoContributorIssueDraftGeneratePath(path)) return true;
if (path === LINT_PR_TEXT_PATH || path === LINT_SLOP_RISK_PATH || path === LINT_ISSUE_SLOP_PATH) return true;
if (path === EXTENSION_PULL_CONTEXT_PATH && isExtensionScopedSession(identity)) return true;
Expand Down Expand Up @@ -5107,7 +5107,7 @@ function isRepoAgentAuditFeedPath(path: string): boolean {
return /^\/v1\/repos\/[^/]+\/[^/]+\/agent\/audit-feed$/.test(path);
}

function isRepoAgentPendingActionsPath(path: string): boolean { return /^\/v1\/repos\/[^/]+\/[^/]+\/agent\/pending-actions(?:\/[^/]+\/(?:accept|reject))?$/.test(path); }
function isRepoAgentPendingActionsPath(path: string): boolean { return /^\/v1\/repos\/[^/]+\/[^/]+\/agent\/pending-actions$/.test(path); }
function isIssueQualityPath(path: string): boolean {
return /^\/v1\/repos\/[^/]+\/[^/]+\/issue-quality$/.test(path);
}
Expand Down
18 changes: 18 additions & 0 deletions test/unit/routes-agent-approval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ describe("agent approval-queue routes (#779)", () => {
await expect(list.json()).resolves.toMatchObject({ repoFullName: "owner/repo", pendingActions: [{ actionClass: "merge", status: "pending" }] });
});

it("forbids repository owner browser sessions from deciding pending actions", async () => {
const env = createTestEnv({ ADMIN_GITHUB_LOGINS: "" });
await upsertInstallation(env, {
installation: { id: 5, account: { login: "owner", id: 1, type: "User" }, repository_selection: "selected", permissions: { metadata: "read", contents: "write", pull_requests: "write", issues: "write" }, events: ["pull_request"] },
repositories: [{ name: "repo", full_name: "owner/repo", private: false, owner: { login: "owner" } }],
});
await upsertRepositoryFromGitHub(env, { name: "repo", full_name: "owner/repo", private: false, owner: { login: "owner" } }, 5);
const action = await seedPending(env);
const { token } = await createSessionForGitHubUser(env, { login: "owner", id: 1 });

const res = await app.request(`/v1/repos/owner/repo/agent/pending-actions/${action.id}/accept`, { method: "POST", headers: { cookie: `gittensory_session=${token}`, origin: "https://preview.example" } }, env);

expect(res.status).toBe(403);
await expect(res.json()).resolves.toMatchObject({ error: "insufficient_role" });
expect(mergePullRequest).not.toHaveBeenCalled();
expect((await getPendingAgentAction(env, action.id))?.status).toBe("pending");
});

it("forbids a contributor (non-maintainer) session even though the coarse allowlist permits the path", async () => {
const env = createTestEnv({ ADMIN_GITHUB_LOGINS: "" });
await upsertInstallation(env, {
Expand Down
Loading