sverka 0.2.30 → 0.2.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2630,10 +2630,23 @@ async function applyGitlabComment(write, declarations) {
2630
2630
  await postJson(`${api}${on === "merge_request" ? `/projects/${encodeURIComponent(project)}/merge_requests/${iid}/notes` : `/projects/${encodeURIComponent(project)}/issues/${iid}/notes`}`, token, { body }, "PRIVATE-TOKEN");
2631
2631
  return `comment on ${on} !${iid}`;
2632
2632
  }
2633
+ /** The provider API base must be https — the apply token and the comment
2634
+ * body travel with every request, so a plaintext base would put both on
2635
+ * the wire in the clear. */
2636
+ function requireHttpsApi(url) {
2637
+ let parsed;
2638
+ try {
2639
+ parsed = new URL(url);
2640
+ } catch {
2641
+ throw new CliError(`sverka apply: provider API URL is not a valid URL: ${url}`, "PACKAGE_ERROR", ExitCode.RuntimeError);
2642
+ }
2643
+ if (parsed.protocol !== "https:") throw new CliError("sverka apply: provider API URL must be https", "PACKAGE_ERROR", ExitCode.RuntimeError);
2644
+ return url;
2645
+ }
2633
2646
  /** Provider-supplied env for a GitLab apply call — all CI-controlled. */
2634
2647
  function gitlabApplyEnv() {
2635
2648
  const env = process$1.env;
2636
- const api = env["CI_API_V4_URL"] ?? "https://gitlab.com/api/v4";
2649
+ const api = requireHttpsApi(env["CI_API_V4_URL"] ?? "https://gitlab.com/api/v4");
2637
2650
  const project = env["CI_PROJECT_ID"];
2638
2651
  if (project === void 0 || project === "") throw new CliError("sverka apply: CI_PROJECT_ID is not set — run inside a GitLab job or set it explicitly", "MISSING_ARG", ExitCode.RuntimeError);
2639
2652
  const token = env["SVERKA_APPLY_TOKEN"] || env["GITLAB_TOKEN"];
@@ -2646,7 +2659,7 @@ function gitlabApplyEnv() {
2646
2659
  }
2647
2660
  async function applyGithubComment(write) {
2648
2661
  const env = process$1.env;
2649
- const api = env["GITHUB_API_URL"] ?? "https://api.github.com";
2662
+ const api = requireHttpsApi(env["GITHUB_API_URL"] ?? "https://api.github.com");
2650
2663
  const repo = env["GITHUB_REPOSITORY"];
2651
2664
  if (repo === void 0 || repo === "") throw new CliError("sverka apply: GITHUB_REPOSITORY is not set — run inside a GitHub Actions job or set it explicitly", "MISSING_ARG", ExitCode.RuntimeError);
2652
2665
  const token = env["SVERKA_APPLY_TOKEN"] || env["GH_TOKEN"] || env["GITHUB_TOKEN"];
@@ -2663,7 +2676,8 @@ async function postJson(url, token, body, auth) {
2663
2676
  const res = await fetch(url, {
2664
2677
  method: "POST",
2665
2678
  headers,
2666
- body: JSON.stringify(body)
2679
+ body: JSON.stringify(body),
2680
+ redirect: "error"
2667
2681
  });
2668
2682
  if (!res.ok) {
2669
2683
  const text = await res.text().catch(() => "");