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
9 changes: 7 additions & 2 deletions src/github/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ async function createOrUpdateIssueCommentWithMarker(
marker: string,
options: { createIfMissing?: boolean | undefined; mode?: AgentActionMode } = {},
): Promise<{ id: number; html_url?: string } | null> {
const [owner, repo] = repoFullName.split("/");
if (!owner || !repo) throw new Error(`Invalid repository full name: ${repoFullName}`);
const parts = repoFullName.split("/");
const owner = parts[0];
const repo = parts[1];
// Reject anything that is not exactly two non-empty segments -- "owner/repo/extra" would otherwise pass
// (the destructure silently drops the extra segment), issuing a call against a repo the caller never
// specified. Matches the segment-count guard in parseRepoFullName (assignees.ts / labels.ts).
if (parts.length !== 2 || !owner || !repo) throw new Error(`Invalid repository full name: ${repoFullName}`);

return await withInstallationTokenRetry(env, installationId, async (token) => {
// Non-live mode suppresses the comment create/update writes; the GET marker-search probe below still runs.
Expand Down
8 changes: 8 additions & 0 deletions test/unit/github-comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ describe("GitHub PR intelligence comments", () => {
it("rejects invalid repository names before calling GitHub", async () => {
await expect(createOrUpdatePrIntelligenceComment(createTestEnv(), 123, "invalid", 12, "body")).rejects.toThrow(/Invalid repository full name/);
});

it("rejects a malformed three-segment repository name instead of silently truncating it", async () => {
// "owner/repo/extra" splits into three segments; the extra one must be rejected, not dropped, so no
// GitHub call is ever made against the truncated "owner/repo".
await expect(createOrUpdatePrIntelligenceComment(createTestEnv(), 123, "owner/repo/extra", 12, "body")).rejects.toThrow(
/Invalid repository full name/,
);
});
});

async function generatePrivateKeyPem(): Promise<string> {
Expand Down