//native
type Vercel = {
token: string;
};
/**
* Update Firewall Configuration
* Process updates to modify the existing firewall config for a project
*/
export async function main(
auth: Vercel,
projectId: string | undefined,
teamId: string | undefined,
slug: string | undefined,
body:
| { action: "firewallEnabled"; id?: null; value: false | true }
| {
action: "rules.insert";
id?: null;
value: {
name: string;
description?: string;
active: false | true;
conditionGroup: {
conditions: {
type:
| "host"
| "path"
| "method"
| "header"
| "query"
| "cookie"
| "target_path"
| "raw_path"
| "ip_address"
| "region"
| "protocol"
| "scheme"
| "environment"
| "user_agent"
| "geo_continent"
| "geo_country"
| "geo_country_region"
| "geo_city"
| "geo_as_number"
| "ja4_digest"
| "ja3_digest"
| "rate_limit_api_id";
op:
| "re"
| "eq"
| "neq"
| "ex"
| "nex"
| "inc"
| "ninc"
| "pre"
| "suf"
| "sub"
| "gt"
| "gte"
| "lt"
| "lte";
neg?: false | true;
key?: string;
value?: string | number | string[];
}[];
}[];
action: {
mitigate?: {
action:
| "log"
| "challenge"
| "deny"
| "bypass"
| "rate_limit"
| "redirect";
rateLimit?: {
algo: "fixed_window" | "token_bucket";
window: number;
limit: number;
keys: string[];
action?: "log" | "challenge" | "deny" | "rate_limit";
};
redirect?: { location: string; permanent: false | true };
actionDuration?: string;
bypassSystem?: false | true;
};
};
};
}
| {
action: "rules.update";
id: string;
value: {
name: string;
description?: string;
active: false | true;
conditionGroup: {
conditions: {
type:
| "host"
| "path"
| "method"
| "header"
| "query"
| "cookie"
| "target_path"
| "raw_path"
| "ip_address"
| "region"
| "protocol"
| "scheme"
| "environment"
| "user_agent"
| "geo_continent"
| "geo_country"
| "geo_country_region"
| "geo_city"
| "geo_as_number"
| "ja4_digest"
| "ja3_digest"
| "rate_limit_api_id";
op:
| "re"
| "eq"
| "neq"
| "ex"
| "nex"
| "inc"
| "ninc"
| "pre"
| "suf"
| "sub"
| "gt"
| "gte"
| "lt"
| "lte";
neg?: false | true;
key?: string;
value?: string | number | string[];
}[];
}[];
action: {
mitigate?: {
action:
| "log"
| "challenge"
| "deny"
| "bypass"
| "rate_limit"
| "redirect";
rateLimit?: {
algo: "fixed_window" | "token_bucket";
window: number;
limit: number;
keys: string[];
action?: "log" | "challenge" | "deny" | "rate_limit";
};
redirect?: { location: string; permanent: false | true };
actionDuration?: string;
bypassSystem?: false | true;
};
};
};
}
| { action: "rules.remove"; id: string; value?: null }
| { action: "rules.priority"; id: string; value: number }
| {
action: "crs.update";
id:
| "sd"
| "ma"
| "lfi"
| "rfi"
| "rce"
| "php"
| "gen"
| "xss"
| "sqli"
| "sf"
| "java";
value: { active: false | true; action: "log" | "deny" };
}
| { action: "crs.disable"; id?: null; value?: null }
| {
action: "ip.insert";
id?: null;
value: {
hostname: string;
ip: string;
notes?: string;
action: "log" | "challenge" | "deny" | "bypass";
};
}
| {
action: "ip.update";
id: string;
value: {
hostname: string;
ip: string;
notes?: string;
action: "log" | "challenge" | "deny" | "bypass";
};
}
| { action: "ip.remove"; id: string; value?: null }
| {
action: "managedRules.update";
id: string;
value: { action?: "log" | "challenge" | "deny"; active: false | true };
}
| { action: "managedRuleGroup.update"; id: string; value: {} },
) {
const url = new URL(`https://api.vercel.com/v1/security/firewall/config`);
for (const [k, v] of [
["projectId", projectId],
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago