Deployment protection bypass (#298)
* test preview bypass 2 Co-authored-by: Cursor <cursoragent@cursor.com> * add apiFetch wrapper with Vercel bypass via query param + header the template workflow was missing VERCEL_AUTOMATION_BYPASS_SECRET, so all action API calls to preview deployments hit Vercel's deployment protection without bypass. this also consolidates the bypass logic into a single fetch wrapper that applies the secret as both a query parameter (matching server-side forwarding) and a header for belt-and-suspenders reliability. Co-authored-by: Cursor <cursoragent@cursor.com> * security hardening for Vercel bypass - redact bypass token from webhook forwarder logs and response body - remove dead x-preview-api-forward header - refactor getAllSecrets() to use SENSITIVE_PATTERNS instead of hardcoded list - enforce https:// on API_URL (localhost exempt for local dev) Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
pullfrog[bot]
parent
d5508d99bb
commit
6f108237d4
@@ -139417,15 +139417,43 @@ var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRes
|
||||
);
|
||||
|
||||
// utils/apiUrl.ts
|
||||
function getApiUrl() {
|
||||
const url4 = process.env.API_URL || "https://pullfrog.com";
|
||||
log.debug(`resolved API_URL: ${url4}`);
|
||||
return url4;
|
||||
function isLocalUrl(url4) {
|
||||
return url4.hostname === "localhost" || url4.hostname === "127.0.0.1";
|
||||
}
|
||||
function getVercelBypassHeaders() {
|
||||
const secret = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
|
||||
if (!secret) return {};
|
||||
return { "x-vercel-protection-bypass": secret };
|
||||
function getApiUrl() {
|
||||
const raw = process.env.API_URL || "https://pullfrog.com";
|
||||
const parsed2 = new URL(raw);
|
||||
if (parsed2.protocol !== "https:" && !isLocalUrl(parsed2)) {
|
||||
throw new Error(
|
||||
`API_URL must use https:// (got ${parsed2.protocol}). only localhost is exempt.`
|
||||
);
|
||||
}
|
||||
log.debug(`resolved API_URL: ${raw}`);
|
||||
return raw;
|
||||
}
|
||||
|
||||
// utils/apiFetch.ts
|
||||
async function apiFetch(options) {
|
||||
const apiUrl = getApiUrl();
|
||||
const url4 = new URL(options.path, apiUrl);
|
||||
const bypassSecret = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
|
||||
if (bypassSecret) {
|
||||
url4.searchParams.set("x-vercel-protection-bypass", bypassSecret);
|
||||
}
|
||||
const headers = {
|
||||
...options.headers
|
||||
};
|
||||
if (bypassSecret) {
|
||||
headers["x-vercel-protection-bypass"] = bypassSecret;
|
||||
}
|
||||
log.debug(`api fetch: ${options.method ?? "GET"} ${url4.pathname}`);
|
||||
const init = {
|
||||
method: options.method ?? "GET",
|
||||
headers
|
||||
};
|
||||
if (options.body) init.body = options.body;
|
||||
if (options.signal) init.signal = options.signal;
|
||||
return fetch(url4.toString(), init);
|
||||
}
|
||||
|
||||
// utils/retry.ts
|
||||
@@ -139465,37 +139493,26 @@ function isOIDCAvailable() {
|
||||
}
|
||||
async function acquireTokenViaOIDC(opts) {
|
||||
const oidcToken = await core2.getIDToken("pullfrog-api");
|
||||
const apiUrl = getApiUrl();
|
||||
const params = new URLSearchParams();
|
||||
const repos = [...opts?.repos ?? []];
|
||||
const targetRepo = process.env.GITHUB_REPOSITORY?.split("/")[1];
|
||||
if (targetRepo) {
|
||||
repos.push(targetRepo);
|
||||
}
|
||||
if (repos.length) {
|
||||
params.set("repos", repos.join(","));
|
||||
}
|
||||
const queryString = params.toString() ? `?${params.toString()}` : "";
|
||||
const reposParam = repos.length ? `?repos=${repos.join(",")}` : "";
|
||||
const timeoutMs = 3e4;
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const fetchOptions = {
|
||||
const tokenResponse = await apiFetch({
|
||||
path: `/api/github/installation-token${reposParam}`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${oidcToken}`,
|
||||
"Content-Type": "application/json",
|
||||
...getVercelBypassHeaders()
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: opts?.permissions ? JSON.stringify({ permissions: opts.permissions }) : void 0,
|
||||
signal: controller.signal
|
||||
};
|
||||
if (opts?.permissions) {
|
||||
fetchOptions.body = JSON.stringify({ permissions: opts.permissions });
|
||||
}
|
||||
const tokenResponse = await fetch(
|
||||
`${apiUrl}/api/github/installation-token${queryString}`,
|
||||
fetchOptions
|
||||
);
|
||||
});
|
||||
clearTimeout(timeoutId);
|
||||
if (!tokenResponse.ok) {
|
||||
throw new Error(`Token exchange failed: ${tokenResponse.status} ${tokenResponse.statusText}`);
|
||||
@@ -144006,13 +144023,12 @@ function UploadFileTool(ctx) {
|
||||
const contentLength = buffer.length;
|
||||
const fileType = await fileTypeFromBuffer(buffer);
|
||||
const contentType = fileType?.mime || "application/octet-stream";
|
||||
const apiUrl = getApiUrl();
|
||||
const response = await fetch(`${apiUrl}/api/upload/signed-url`, {
|
||||
const response = await apiFetch({
|
||||
path: "/api/upload/signed-url",
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.apiToken}`,
|
||||
"Content-Type": "application/json",
|
||||
...getVercelBypassHeaders()
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
filename,
|
||||
@@ -146718,23 +146734,18 @@ var defaultRunContext = {
|
||||
apiToken: ""
|
||||
};
|
||||
async function fetchRunContext(params) {
|
||||
const apiUrl = getApiUrl();
|
||||
const timeoutMs = 3e4;
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${apiUrl}/api/repo/${params.repoContext.owner}/${params.repoContext.name}/run-context`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${params.token}`,
|
||||
"Content-Type": "application/json",
|
||||
...getVercelBypassHeaders()
|
||||
},
|
||||
signal: controller.signal
|
||||
}
|
||||
);
|
||||
const response = await apiFetch({
|
||||
path: `/api/repo/${params.repoContext.owner}/${params.repoContext.name}/run-context`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${params.token}`,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
signal: controller.signal
|
||||
});
|
||||
clearTimeout(timeoutId);
|
||||
if (!response.ok) {
|
||||
return defaultRunContext;
|
||||
|
||||
Reference in New Issue
Block a user