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: integration security and quality issues, add Discord/Slack docs

Andrej3953cb4a32e3
diff --git a/apps/api/src/database/schema.ts b/apps/api/src/database/schema.ts
index f6fd0662b..e46fcef0e 100644
--- a/apps/api/src/database/schema.ts
+++ b/apps/api/src/database/schema.ts
@@ -445,7 +445,10 @@ export const githubIntegrationTable = pgTable("github_integration", {
installationId: integer("installation_id"),
isActive: boolean("is_active").default(true),
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { mode: "date" })
+ .defaultNow()
+ .$onUpdate(() => new Date())
+ .notNull(),
});
export const integrationTable = pgTable(
diff --git a/apps/api/src/generic-webhook-integration/index.ts b/apps/api/src/generic-webhook-integration/index.ts
index 609e60e76..4db165bda 100644
--- a/apps/api/src/generic-webhook-integration/index.ts
+++ b/apps/api/src/generic-webhook-integration/index.ts
@@ -26,7 +26,7 @@ const genericWebhookIntegration = new Hono<{
};
}>();
-function maskSecret(value: string | undefined): string | null {
+function maskValue(value: string | undefined): string | null {
if (!value) return null;
return value.length > 8 ? `${value.slice(0, 4)}…${value.slice(-4)}` : "••••";
}
@@ -47,9 +47,9 @@ function toResponse(integration: {
id: integration.id,
projectId: integration.projectId,
webhookConfigured: Boolean(config.webhookUrl),
- webhookUrl: config.webhookUrl,
+ maskedWebhookUrl: maskValue(config.webhookUrl),
secretConfigured: Boolean(config.secret),
- maskedSecret: maskSecret(config.secret),
+ maskedSecret: maskValue(config.secret),
events: {
...defaultGenericWebhookEvents,
...(config.events ?? {}),
diff --git a/apps/api/src/github-integration/index.ts b/apps/api/src/github-integration/index.ts
index f1e775292..ac12451d1 100644
--- a/apps/api/src/github-integration/index.ts
+++ b/apps/api/src/github-integration/index.ts
@@ -333,8 +333,7 @@ const githubIntegration = new Hono<{
throw new HTTPException(401, { message: "Unauthorized" });
}
- const body = await c.req.json();
- const projectId = body.projectId as string;
+ const { projectId } = c.req.valid("json");
const [project] = await db
.select({ workspaceId: projectTable.workspaceId })
diff --git a/apps/api/src/plugins/generic-webhook/client.ts b/apps/api/src/plugins/generic-webhook/client.ts
index c1e6f21cc..464d4c0fb 100644
--- a/apps/api/src/plugins/generic-webhook/client.ts
+++ b/apps/api/src/plugins/generic-webhook/client.ts
@@ -1,88 +1,10 @@
import { createHmac } from "node:crypto";
-import { lookup } from "node:dns/promises";
-import net from "node:net";
+import { assertPublicWebhookDestination } from "./config";
type GenericWebhookPayload = Record<string, unknown>;
const GENERIC_WEBHOOK_TIMEOUT_MS = 10_000;
-function isDisallowedIpv4(ip: string): boolean {
- const parts = ip.split(".").map((part) => Number.parseInt(part, 10));
- if (parts.length !== 4 || parts.some(Number.isNaN)) {
- return true;
- }
-
- const [a, b] = parts;
-
- return (
- a === 0 ||
- a === 10 ||
- a === 127 ||
- (a === 169 && b === 254) ||
- (a === 172 && b >= 16 && b <= 31) ||
- (a === 192 && b === 168)
- );
-}
-
-function isDisallowedIpv6(ip: string): boolean {
- const normalized = ip.toLowerCase();
-
- return (
- normalized === "::" ||
- normalized === "::1" ||
- normalized.startsWith("fe8") ||
- normalized.startsWith("fe9") ||
- normalized.startsWith("fea") ||
- normalized.startsWith("feb") ||
- normalized.startsWith("fc") ||
- normalized.startsWith("fd")
- );
-}
-
-function isDisallowedAddress(address: string): boolean {
- if (address === "localhost") {
- return true;
- }
-
- const version = net.isIP(address);
- if (version === 4) {
- return isDisallowedIpv4(address);
- }
-
- if (version === 6) {
- return isDisallowedIpv6(address);
- }
-
- return false;
-}
-
-async function assertPublicWebhookDestination(
- webhookUrl: string,
-): Promise<void> {
- const url = new URL(webhookUrl);
-
- if (!["http:", "https:"].includes(url.protocol)) {
- throw new Error("Generic webhook URL must use http or https");
- }
-
- if (isDisallowedAddress(url.hostname)) {
- throw new Error(
- "Generic webhook destination resolves to a non-routable address",
- );
- }
-
- const addresses = await lookup(url.hostname, { all: true, verbatim: true });
- if (addresses.length === 0) {
- throw new Error("Generic webhook destination could not be resolved");
- }
-
- if (addresses.some((entry) => isDisallowedAddress(entry.address))) {
- throw new Error(
- "Generic webhook destination resolves to a non-routable address",
- );
- }
-}
-
export async function postToGenericWebhook(
webhookUrl: string,
payload: GenericWebhookPayload,
diff --git a/apps/api/src/plugins/generic-webhook/config.ts b/apps/api/src/plugins/generic-webhook/config.ts
index b1ddb6b4b..f864426bb 100644
--- a/apps/api/src/plugins/generic-webhook/config.ts
+++ b/apps/api/src/plugins/generic-webhook/config.ts
@@ -1,5 +1,84 @@
+import { lookup } from "node:dns/promises";
+import net from "node:net";
import * as v from "valibot";
+function isDisallowedIpv4(ip: string): boolean {
+ const parts = ip.split(".").map((part) => Number.parseInt(part, 10));
+ if (parts.length !== 4 || parts.some(Number.isNaN)) {
+ return true;
+ }
+
+ const [a, b] = parts;
+
+ return (
+ a === 0 ||
+ a === 10 ||
+ a === 127 ||
+ (a === 169 && b === 254) ||
+ (a === 172 && b >= 16 && b <= 31) ||
+ (a === 192 && b === 168)
+ );
+}
+
+function isDisallowedIpv6(ip: string): boolean {
+ const normalized = ip.toLowerCase();
+
+ return (
+ normalized === "::" ||
+ normalized === "::1" ||
+ normalized.startsWith("fe8") ||
+ normalized.startsWith("fe9") ||
+ normalized.startsWith("fea") ||
+ normalized.startsWith("feb") ||
+ normalized.startsWith("fc") ||
+ normalized.startsWith("fd")
+ );
+}
+
+function isDisallowedAddress(address: string): boolean {
+ if (address === "localhost") {
+ return true;
+ }
+
+ const version = net.isIP(address);
+ if (version === 4) {
+ return isDisallowedIpv4(address);
+ }
+
+ if (version === 6) {
+ return isDisallowedIpv6(address);
+ }
+
+ return false;
+}
+
+export async function assertPublicWebhookDestination(
+ webhookUrl: string,
+): Promise<void> {
+ const url = new URL(webhookUrl);
+
+ if (!["http:", "https:"].includes(url.protocol)) {
+ throw new Error("Generic webhook URL must use http or https");
+ }
+
+ if (isDisallowedAddress(url.hostname)) {
+ throw new Error(
+ "Generic webhook destination resolves to a non-routable address",
+ );
+ }
+
+ const addresses = await lookup(url.hostname, { all: true, verbatim: true });
+ if (addresses.length === 0) {
+ throw new Error("Generic webhook destination could not be resolved");
+ }
+
+ if (addresses.some((entry) => isDisallowedAddress(entry.address))) {
+ throw new Error(
+ "Generic webhook destination resolves to a non-routable address",
+ );
+ }
+}
+
export const genericWebhookEventKeys = [
"taskCreated",
"taskStatusChanged",
@@ -93,7 +172,8 @@ export async function validateGenericWebhookConfig(
config: unknown,
): Promise<{ valid: boolean; errors?: string[] }> {
try {
- v.parse(genericWebhookConfigSchema, config);
+ const parsed = v.parse(genericWebhookConfigSchema, config);
+ await assertPublicWebhookDestination(parsed.webhookUrl);
return { valid: true };
} catch (error) {
if (error instanceof v.ValiError) {
diff --git a/apps/docs/core/integrations/discord.mdx b/apps/docs/core/integrations/discord.mdx
new file mode 100644
index 000000000..132f18d48
--- /dev/null
+++ b/apps/docs/core/integrations/discord.mdx
@@ -0,0 +1,68 @@
+---
+title: Discord
+description: Send task notifications from Kaneo to a Discord channel using incoming webhooks.
+---
+
+Kaneo can post task activity to a Discord channel whenever events occur in a project. This uses Discord's incoming webhook feature — no bot or OAuth setup required.
+
+## Create a Discord webhook
+
+1. Open Discord and go to the channel you want notifications in.
+2. Click the gear icon to open **Channel Settings**.
+3. Go to **Integrations** then **Webhooks**.
+4. Click **New Webhook**.
+5. Give the webhook a name (e.g. "Kaneo") and optionally set an avatar.
+6. Click **Copy Webhook URL**. It will look like:
+
+```
+https://discord.com/api/webhooks/000000000000000000/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+```
+
+<Info>
+URLs using `discordapp.com` are also accepted.
+</Info>
+
+## Connect Discord in Kaneo
+
+1. Open **Settings** in the sidebar.
+2. Under **Projects**, select the project you want to connect.
+3. Open the **Integrations** tab.
+4. Expand the **Discord** section.
+5. Paste your webhook URL.
+6. Optionally add a channel name label for your own reference.
+7. Choose which events to subscribe to (see below).
+8. Click **Connect**.
+
+Once connected you can enable or disable the integration with the toggle, update event subscriptions, or disconnect entirely.
+
+## Supported events
+
+| Event | Default | Description |
+| --- | --- | --- |
+| Task created | On | A new task is created in the project |
+| Task status changed | On | A task moves to a different status column |
+| Task priority changed | Off | A task's priority is changed |
+| Task title changed | Off | A task's title is edited |
+| Task description changed | Off | A task's description is edited |
+| Task comment created | On | A new comment is added to a task |
+
+You can toggle any combination of these events in the integration settings at any time.
+
+## Message format
+
+Kaneo sends Discord embed messages with:
+
+- A title describing the event (e.g. "Task Status Changed")
+- Task name with a clickable link to the task in Kaneo
+- Fields for project, status, and priority
+- The name of the user who triggered the event
+
+Make sure [`KANEO_CLIENT_URL`](/core/installation/environment-variables) is set to your public Kaneo URL so task links work correctly.
+
+## Updating the webhook
+
+To change the webhook URL after connecting, paste the new URL in the webhook field and click **Save Changes**. If you leave the field empty, the existing URL is kept.
+
+## Disconnecting
+
+Click **Disconnect** to remove the integration. This deletes the stored webhook URL and all event settings for that project. You can reconnect at any time by pasting a new webhook URL.
diff --git a/apps/docs/core/integrations/slack.mdx b/apps/docs/core/integrations/slack.mdx
new file mode 100644
index 000000000..f19c82555
--- /dev/null
+++ b/apps/docs/core/integrations/slack.mdx
@@ -0,0 +1,68 @@
+---
+title: Slack
+description: Send task notifications from Kaneo to a Slack channel using incoming webhooks.
+---
+
+Kaneo can post task activity to a Slack channel whenever events occur in a project. This uses Slack's incoming webhook feature — no bot token or OAuth flow required.
+
+## Create a Slack webhook
+
+1. Go to [api.slack.com/apps](https://api.slack.com/apps) and click **Create New App** then **From scratch**.
+2. Name your app (e.g. "Kaneo") and select your workspace.
+3. In the app settings, go to **Incoming Webhooks** and toggle it **On**.
+4. Click **Add New Webhook to Workspace**.
+5. Select the channel where you want notifications (or choose your own DM for personal notifications).
+6. Click **Allow**, then copy the webhook URL. It will look like:
+
+```
+https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
+```
+
+<Warning>
+If your Slack workspace restricts app installations, you may need a workspace admin to approve the app before you can use the webhook.
+</Warning>
+
+## Connect Slack in Kaneo
+
+1. Open **Settings** in the sidebar.
+2. Under **Projects**, select the project you want to connect.
+3. Open the **Integrations** tab.
+4. Expand the **Slack** section.
+5. Paste your webhook URL.
+6. Optionally add a channel name label for your own reference.
+7. Choose which events to subscribe to (see below).
+8. Click **Connect**.
+
+Once connected you can enable or disable the integration with the toggle, update event subscriptions, or disconnect entirely.
+
+## Supported events
+
+| Event | Default | Description |
+| --- | --- | --- |
+| Task created | On | A new task is created in the project |
+| Task status changed | On | A task moves to a different status column |
+| Task priority changed | Off | A task's priority is changed |
+| Task title changed | Off | A task's title is edited |
+| Task description changed | Off | A task's description is edited |
+| Task comment created | On | A new comment is added to a task |
+
+You can toggle any combination of these events in the integration settings at any time.
+
+## Message format
+
+Kaneo sends Slack Block Kit messages with:
+
+- A header describing the event (e.g. "Task Status Changed")
+- Task name with a clickable link to the task in Kaneo
+- Fields for project, status, and priority
+- The name of the user who triggered the event
+
+Make sure [`KANEO_CLIENT_URL`](/core/installation/environment-variables) is set to your public Kaneo URL so task links work correctly.
+
+## Updating the webhook
+
+To change the webhook URL after connecting, paste the new URL in the webhook field and click **Save Changes**. If you leave the field empty, the existing URL is kept.
+
+## Disconnecting
+
+Click **Disconnect** to remove the integration. This deletes the stored webhook URL and all event settings for that project. You can reconnect at any time by pasting a new webhook URL.
diff --git a/apps/docs/docs.json b/apps/docs/docs.json
index a201da976..116386f78 100644
--- a/apps/docs/docs.json
+++ b/apps/docs/docs.json
@@ -80,8 +80,12 @@
]
},
{
- "group": "Outgoing webhooks",
- "pages": ["core/integrations/outgoing-webhooks"]
+ "group": "Integrations",
+ "pages": [
+ "core/integrations/discord",
+ "core/integrations/slack",
+ "core/integrations/outgoing-webhooks"
+ ]
},
{
"group": "Authentication Providers",
diff --git a/apps/web/src/components/project/generic-webhook-integration-settings.tsx b/apps/web/src/components/project/generic-webhook-integration-settings.tsx
index 7e07ae335..081468453 100644
--- a/apps/web/src/components/project/generic-webhook-integration-settings.tsx
+++ b/apps/web/src/components/project/generic-webhook-integration-settings.tsx
@@ -104,7 +104,7 @@ export function GenericWebhookIntegrationSettings({
const normalizedValues = React.useMemo<GenericWebhookIntegrationFormValues>(
() => ({
- webhookUrl: integration?.webhookUrl ?? "",
+ webhookUrl: "",
secret: "",
taskCreated: integration?.events?.taskCreated ?? true,
taskStatusChanged: integration?.events?.taskStatusChanged ?? true,
diff --git a/apps/web/src/components/project/slack-integration-settings.tsx b/apps/web/src/components/project/slack-integration-settings.tsx
index 2508528df..731d6fb0b 100644
--- a/apps/web/src/components/project/slack-integration-settings.tsx
+++ b/apps/web/src/components/project/slack-integration-settings.tsx
@@ -70,6 +70,15 @@ function EventToggle({
);
}
+function isValidSlackWebhookUrl(value: string): boolean {
+ return (
+ z.url().safeParse(value).success &&
+ /^https:\/\/hooks\.slack\.com\/services\/[A-Za-z0-9]+\/[A-Za-z0-9]+\/[A-Za-z0-9]+$/i.test(
+ value,
+ )
+ );
+}
+
export function SlackIntegrationSettings({ projectId }: { projectId: string }) {
const { t } = useTranslation();
const schema = React.useMemo(
@@ -122,10 +131,18 @@ export function SlackIntegrationSettings({ projectId }: { projectId: string }) {
taskCommentCreated: true,
},
});
+ const { reset } = form;
+ const lastResetKeyRef = React.useRef<string | null>(null);
+ const resetKey = `${projectId}:${integration?.id ?? "none"}`;
React.useEffect(() => {
- form.reset(normalizedValues);
- }, [form, normalizedValues]);
+ if (form.formState.isDirty && lastResetKeyRef.current === resetKey) {
+ return;
+ }
+
+ reset(normalizedValues);
+ lastResetKeyRef.current = resetKey;
+ }, [form.formState.isDirty, normalizedValues, reset, resetKey]);
const isConnected = Boolean(integration?.webhookConfigured);
const isBusy = isCreating || isUpdating || isDeleting;
@@ -143,10 +160,7 @@ export function SlackIntegrationSettings({ projectId }: { projectId: string }) {
};
if (!isConnected) {
- if (
- !trimmedWebhookUrl ||
- !z.url().safeParse(trimmedWebhookUrl).success
- ) {
+ if (!trimmedWebhookUrl || !isValidSlackWebhookUrl(trimmedWebhookUrl)) {
form.setError("webhookUrl", {
message: t("settings:slackIntegration.validation.webhookInvalid"),
});
@@ -162,10 +176,7 @@ export function SlackIntegrationSettings({ projectId }: { projectId: string }) {
},
});
} else {
- if (
- trimmedWebhookUrl &&
- !z.url().safeParse(trimmedWebhookUrl).success
- ) {
+ if (trimmedWebhookUrl && !isValidSlackWebhookUrl(trimmedWebhookUrl)) {
form.setError("webhookUrl", {
message: t("settings:slackIntegration.validation.webhookInvalid"),
});
diff --git a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
index 0c81bb0ef..7fd06bb70 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
@@ -4,7 +4,7 @@ export type GenericWebhookIntegration = {
id: string;
projectId: string;
webhookConfigured: boolean;
- webhookUrl: string;
+ maskedWebhookUrl: string | null;
secretConfigured: boolean;
maskedSecret: string | null;
events: {