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): stop returning integration secrets from the external-link route

Andrej3ac5aa97fd73
diff --git a/apps/api/src/external-link/index.ts b/apps/api/src/external-link/index.ts
index fb4ec3555..95c496404 100644
--- a/apps/api/src/external-link/index.ts
+++ b/apps/api/src/external-link/index.ts
@@ -49,7 +49,9 @@ const externalLink = new Hono<{
const links = await db.query.externalLinkTable.findMany({
where: eq(externalLinkTable.taskId, taskId),
with: {
- integration: true,
+ // Never widen this: integration.config holds plaintext provider
+ // secrets and this route is reachable by any workspace member.
+ integration: { columns: { id: true, type: true } },
},
});
diff --git a/apps/web/src/types/external-link/index.ts b/apps/web/src/types/external-link/index.ts
index e2dacc784..6752cd768 100644
--- a/apps/web/src/types/external-link/index.ts
+++ b/apps/web/src/types/external-link/index.ts
@@ -28,6 +28,5 @@ export type ExternalLink = {
integration?: {
id: string;
type: string;
- config: string;
};
};
diff --git a/tests/api-integration/external-link-secrets.test.ts b/tests/api-integration/external-link-secrets.test.ts
new file mode 100644
index 000000000..7f201983a
--- /dev/null
+++ b/tests/api-integration/external-link-secrets.test.ts
@@ -0,0 +1,82 @@
+import { beforeEach, describe, expect, it } from "vitest";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+const GITEA_TOKEN = "gitea-pat-should-never-be-exposed";
+const WEBHOOK_SECRET = "gitea-webhook-secret-should-never-be-exposed";
+
+describe("API integration: external link integration secrets", () => {
+ beforeEach(async () => {
+ await resetTestDatabase();
+ });
+
+ it("does not expose integration config to a workspace viewer", async () => {
+ const viewer = await createWorkspaceMember({ role: "viewer" });
+ const { project, columns } = await createProjectFixture({
+ workspaceId: viewer.workspace.id,
+ });
+
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Task with a linked Gitea issue",
+ status: "to-do",
+ columnId: columns.todo.id,
+ priority: "medium",
+ number: 1,
+ position: 1,
+ })
+ .returning();
+
+ const [integration] = await db
+ .insert(schema.integrationTable)
+ .values({
+ projectId: project.id,
+ type: "gitea",
+ config: JSON.stringify({
+ baseUrl: "https://gitea.example",
+ accessToken: GITEA_TOKEN,
+ repositoryOwner: "owner",
+ repositoryName: "repo",
+ webhookSecret: WEBHOOK_SECRET,
+ }),
+ isActive: true,
+ })
+ .returning();
+
+ await db.insert(schema.externalLinkTable).values({
+ taskId: task.id,
+ integrationId: integration.id,
+ resourceType: "issue",
+ externalId: "1",
+ url: "https://gitea.example/owner/repo/issues/1",
+ title: "Linked issue",
+ });
+
+ mockAuthenticatedSession(viewer.user);
+
+ const { app } = createApp();
+ const response = await app.request(`/api/external-link/task/${task.id}`);
+
+ expect(response.status).toBe(200);
+ const body = await response.text();
+
+ expect(body).not.toContain(GITEA_TOKEN);
+ expect(body).not.toContain(WEBHOOK_SECRET);
+ expect(body).not.toContain("config");
+
+ const links = JSON.parse(body);
+ expect(links).toHaveLength(1);
+ expect(links[0].integration).toEqual({
+ id: integration.id,
+ type: "gitea",
+ });
+ });
+});