Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): refuse plain http gitlab url for public hosts

zaralXd48192760db2
diff --git a/apps/api/src/gitlab-integration/utils/normalize-input.ts b/apps/api/src/gitlab-integration/utils/normalize-input.ts
index dfc11a807..309785c2d 100644
--- a/apps/api/src/gitlab-integration/utils/normalize-input.ts
+++ b/apps/api/src/gitlab-integration/utils/normalize-input.ts
@@ -1,5 +1,6 @@
import { HTTPException } from "hono/http-exception";
import {
+ assertGitlabTransport,
normalizeGitlabBaseUrl,
normalizeProjectPath,
} from "../../plugins/gitlab/config";
@@ -15,7 +16,11 @@ function orBadRequest<T>(normalize: () => T): T {
}
export function parseGitlabBaseUrl(url: string): string {
- return orBadRequest(() => normalizeGitlabBaseUrl(url));
+ return orBadRequest(() => {
+ const normalized = normalizeGitlabBaseUrl(url);
+ assertGitlabTransport(normalized);
+ return normalized;
+ });
}
export function parseGitlabProjectPath(path: string): string {
diff --git a/apps/api/src/plugins/gitlab/config.ts b/apps/api/src/plugins/gitlab/config.ts
index 926c3dd73..e817b8a4a 100644
--- a/apps/api/src/plugins/gitlab/config.ts
+++ b/apps/api/src/plugins/gitlab/config.ts
@@ -1,4 +1,5 @@
import * as v from "valibot";
+import { privateDestinationsAllowed } from "../../utils/assert-public-destination";
import { branchPatterns } from "../github/config";
export { branchPatterns };
@@ -75,6 +76,16 @@ export function normalizeGitlabBaseUrl(url: string): string {
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, "")}`;
}
+// The token travels in a request header, so plain http is only accepted for
+// instances on a private network.
+export function assertGitlabTransport(baseUrl: string): void {
+ if (new URL(baseUrl).protocol === "http:" && !privateDestinationsAllowed()) {
+ throw new Error(
+ "GitLab URL must use https unless KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS is enabled",
+ );
+ }
+}
+
// Reject a leading slash or ".." before the path goes into the URL.
export function normalizeProjectPath(path: string): string {
const segments = path
diff --git a/apps/api/src/plugins/gitlab/utils/gitlab-api.ts b/apps/api/src/plugins/gitlab/utils/gitlab-api.ts
index cf33e9282..162dbb45f 100644
--- a/apps/api/src/plugins/gitlab/utils/gitlab-api.ts
+++ b/apps/api/src/plugins/gitlab/utils/gitlab-api.ts
@@ -1,7 +1,11 @@
import * as Sentry from "@sentry/node";
import { assertPublicDestination } from "../../../utils/assert-public-destination";
import type { GitlabConfig, GitlabTokenType } from "../config";
-import { normalizeGitlabBaseUrl, normalizeProjectPath } from "../config";
+import {
+ assertGitlabTransport,
+ normalizeGitlabBaseUrl,
+ normalizeProjectPath,
+} from "../config";
export type GitlabLabel = {
id: number;
@@ -104,6 +108,7 @@ export async function gitlabFetch<T>(
const url = `${root}/api/v4${path.startsWith("/") ? path : `/${path}`}`;
await assertPublicDestination(root, "GitLab");
+ assertGitlabTransport(root);
const controller = new AbortController();
let timedOut = false;
diff --git a/apps/api/src/utils/assert-public-destination.ts b/apps/api/src/utils/assert-public-destination.ts
index 51c67ac17..ceb1b88ba 100644
--- a/apps/api/src/utils/assert-public-destination.ts
+++ b/apps/api/src/utils/assert-public-destination.ts
@@ -78,7 +78,7 @@ export function isDisallowedAddress(address: string): boolean {
return false;
}
-function privateDestinationsAllowed(): boolean {
+export function privateDestinationsAllowed(): boolean {
return (
process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS === "true" ||
process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS === "1"
diff --git a/apps/docs/core/integrations/gitlab/setup.mdx b/apps/docs/core/integrations/gitlab/setup.mdx
index 139a109d1..9ff6a8f7f 100644
--- a/apps/docs/core/integrations/gitlab/setup.mdx
+++ b/apps/docs/core/integrations/gitlab/setup.mdx
@@ -65,6 +65,8 @@ The webhook URL includes your integration id, for example:
By default Kaneo refuses a GitLab URL that resolves to a private or loopback address. If your instance is only reachable inside your network, set `KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS=true` on the API. The same variable lifts the check for Gitea and notification destinations, so only enable it on a trusted deployment.
+Without this variable the GitLab URL must use `https`, since the access token is sent with every request.
+
## What is not synced
- **Confidential issues.** They are skipped on import and ignored when they arrive through the webhook. If an issue is made confidential later, its task keeps the last public content and stops receiving updates.
diff --git a/tests/api/plugins/gitlab-ssrf.test.ts b/tests/api/plugins/gitlab-ssrf.test.ts
index bf1c94c2b..d87302e67 100644
--- a/tests/api/plugins/gitlab-ssrf.test.ts
+++ b/tests/api/plugins/gitlab-ssrf.test.ts
@@ -1,5 +1,7 @@
-import { describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it } from "vitest";
+import { parseGitlabBaseUrl } from "../../../apps/api/src/gitlab-integration/utils/normalize-input";
import {
+ assertGitlabTransport,
normalizeGitlabBaseUrl,
normalizeProjectPath,
} from "../../../apps/api/src/plugins/gitlab/config";
@@ -87,3 +89,45 @@ describe("gitlabFetch destination guard", () => {
});
}
});
+
+describe("GitLab transport", () => {
+ const originalAllowPrivate =
+ process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS;
+
+ afterEach(() => {
+ if (originalAllowPrivate === undefined) {
+ delete process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS;
+ } else {
+ process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS =
+ originalAllowPrivate;
+ }
+ });
+
+ it("does not send a token to a public host over plain http", async () => {
+ delete process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS;
+
+ await expect(
+ gitlabFetch("http://93.184.216.34", "token", "private", "/user"),
+ ).rejects.toThrow(/must use https/);
+ });
+
+ it("rejects a plain http URL entered in the form as a bad request", () => {
+ delete process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS;
+
+ expect(() => parseGitlabBaseUrl("http://gitlab.example.com")).toThrow(
+ expect.objectContaining({ status: 400 }),
+ );
+ });
+
+ it("allows plain http once private destinations are enabled", () => {
+ process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS = "true";
+
+ expect(() => assertGitlabTransport("http://10.0.0.5")).not.toThrow();
+ });
+
+ it("always allows https", () => {
+ delete process.env.KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS;
+
+ expect(() => assertGitlabTransport("https://gitlab.com")).not.toThrow();
+ });
+});