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.
This commit is contained in:
翅膀 committed 2026-10-23 23:21:39 +08:00
1 parent d5e86bb4d9
commit 1b3f353153
2 files changed
+28 -7

No files matched your search

+13 -3
View File
@@ -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<string | undefined> {
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",
+15 -4
View File
@@ -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<WorkflowJob[] | undefined> {
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<string, string> = {
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;