Edits history of script submission #13817 for ' Put Firewall Configuration (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Put Firewall Configuration
     * Set the firewall configuration to provided rules and settings. Creates or overwrite the existing firewall configuration.
     */
    export async function main(
      auth: Vercel,
      projectId: string | undefined,
      teamId: string | undefined,
      slug: string | undefined,
      body: {
        firewallEnabled: false | true;
        managedRules?: {};
        crs?: {
          sd?: { active: false | true; action: "deny" | "log" };
          ma?: { active: false | true; action: "deny" | "log" };
          lfi?: { active: false | true; action: "deny" | "log" };
          rfi?: { active: false | true; action: "deny" | "log" };
          rce?: { active: false | true; action: "deny" | "log" };
          php?: { active: false | true; action: "deny" | "log" };
          gen?: { active: false | true; action: "deny" | "log" };
          xss?: { active: false | true; action: "deny" | "log" };
          sqli?: { active: false | true; action: "deny" | "log" };
          sf?: { active: false | true; action: "deny" | "log" };
          java?: { active: false | true; action: "deny" | "log" };
        };
        rules?: {
          id?: string;
          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:
                | "deny"
                | "log"
                | "challenge"
                | "bypass"
                | "rate_limit"
                | "redirect";
              rateLimit?: {
                algo: "fixed_window" | "token_bucket";
                window: number;
                limit: number;
                keys: string[];
                action?: "deny" | "log" | "challenge" | "rate_limit";
              };
              redirect?: { location: string; permanent: false | true };
              actionDuration?: string;
              bypassSystem?: false | true;
            };
          };
        }[];
        ips?: {
          id?: string;
          hostname: string;
          ip: string;
          notes?: string;
          action: "deny" | "log" | "challenge" | "bypass";
        }[];
      },
    ) {
      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: "PUT",
        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