mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
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:
1 parent
d5e86bb4d9
commit
1b3f353153
2 files changed
+28
-7
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user