From 1b3f353153639487ce7144cdaad633d67982e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Fri, 23 Oct 2026 23:21:39 +0800 Subject: [PATCH] fix(github): restrict enrichment request urls Webhook-provided URLs must never receive an installation token on another host. Restrict enrichment to GitHub repository API paths, reject redirects and bound optional requests. --- server/lib/github/check-run.ts | 16 +++++++++++++--- server/lib/github/workflow-jobs.ts | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/server/lib/github/check-run.ts b/server/lib/github/check-run.ts index bca6210..75f0be4 100644 --- a/server/lib/github/check-run.ts +++ b/server/lib/github/check-run.ts @@ -1,4 +1,10 @@ -import { getInstallationToken, GITHUB_API_VERSION, GITHUB_USER_AGENT } from "./app-token"; +import { + getInstallationToken, + githubApiUrl, + ENRICH_TIMEOUT_MS, + GITHUB_API_VERSION, + GITHUB_USER_AGENT, +} from "./app-token"; const CLOUDFLARE_SLUG = "cloudflare-workers-and-pages"; @@ -18,12 +24,16 @@ export async function getCheckSuiteBuildLogUrl( privateKey: string | undefined, installationId: number | undefined, ): Promise { - if (!checkRunsUrl || !appId || !privateKey || !installationId) return undefined; + const url = githubApiUrl(checkRunsUrl); + if (!url || !appId || !privateKey || !installationId) return undefined; try { const token = await getInstallationToken(appId, privateKey, installationId); if (!token) return undefined; - const runsRes = await fetch(checkRunsUrl, { + // No redirects: a token must never follow a response to another host. + const runsRes = await fetch(url.toString(), { + redirect: "manual", + signal: AbortSignal.timeout(ENRICH_TIMEOUT_MS), headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json", diff --git a/server/lib/github/workflow-jobs.ts b/server/lib/github/workflow-jobs.ts index a1f4ba3..2cef85b 100644 --- a/server/lib/github/workflow-jobs.ts +++ b/server/lib/github/workflow-jobs.ts @@ -1,4 +1,10 @@ -import { getInstallationToken, GITHUB_API_VERSION, GITHUB_USER_AGENT } from "./app-token"; +import { + getInstallationToken, + githubApiUrl, + ENRICH_TIMEOUT_MS, + GITHUB_API_VERSION, + GITHUB_USER_AGENT, +} from "./app-token"; export interface WorkflowJob { name?: string; @@ -24,10 +30,10 @@ export async function getWorkflowRunJobs( privateKey: string | undefined, installationId: number | undefined, ): Promise { - if (!jobsUrl) return undefined; + const url = githubApiUrl(jobsUrl); + if (!url) return undefined; try { const token = await getInstallationToken(appId, privateKey, installationId); - const url = new URL(jobsUrl); url.searchParams.set("per_page", "100"); const headers: Record = { Accept: "application/vnd.github+json", @@ -35,7 +41,12 @@ export async function getWorkflowRunJobs( "User-Agent": GITHUB_USER_AGENT, }; if (token) headers.Authorization = `Bearer ${token}`; - const res = await fetch(url.toString(), { headers }); + // No redirects: a token must never follow a response to another host. + const res = await fetch(url.toString(), { + headers, + redirect: "manual", + signal: AbortSignal.timeout(ENRICH_TIMEOUT_MS), + }); if (!res.ok) return undefined; const data = (await res.json()) as { jobs?: WorkflowJob[] }; return data.jobs?.length ? data.jobs : undefined;