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(integrations): revalidate inbound confirmation repository scope

Tin5a2f16f85a60
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts b/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
index c2c9ec083..442326ee1 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-closed.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../../github/utils/deferred-issue-edit";
import { deferIssueEdit } from "../../github/services/deferred-issue-edits";
import { inboundStamp } from "../../github/utils/sync-echo";
import { withIntegrationLink } from "../../github/services/with-integration-link";
@@ -190,6 +191,10 @@ export async function handleGiteaIssueClosed(
db,
);
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() => deferIssueEdit(externalLink, integration, ["state"]),
);
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
index 4f31962bf..52d6b1f11 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-edited.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../../github/utils/deferred-issue-edit";
import { deferIssueEdit } from "../../github/services/deferred-issue-edits";
import { inboundStamp } from "../../github/utils/sync-echo";
import { publishEvent } from "../../../events";
@@ -212,6 +213,10 @@ export async function handleGiteaIssueEdited(
return;
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() =>
deferIssueEdit(externalLink, integration, [
diff --git a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts b/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
index 224a93a80..d1f002485 100644
--- a/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
+++ b/apps/api/src/plugins/gitea/webhooks/issue-reopened.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../../github/utils/deferred-issue-edit";
import { deferIssueEdit } from "../../github/services/deferred-issue-edits";
import { inboundStamp } from "../../github/utils/sync-echo";
import { withIntegrationLink } from "../../github/services/with-integration-link";
@@ -191,6 +192,10 @@ export async function handleGiteaIssueReopened(
db,
);
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() => deferIssueEdit(externalLink, integration, ["state"]),
);
diff --git a/apps/api/src/plugins/github/webhooks/issue-closed.ts b/apps/api/src/plugins/github/webhooks/issue-closed.ts
index 5d292003a..a3875b39d 100644
--- a/apps/api/src/plugins/github/webhooks/issue-closed.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-closed.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../utils/deferred-issue-edit";
import { deferIssueEdit } from "../services/deferred-issue-edits";
import type { GitHubConfig } from "../config";
import { getVerifiedInstallationOctokit } from "../utils/github-app";
@@ -159,6 +160,10 @@ export async function handleIssueClosed(payload: IssueClosedPayload) {
db,
);
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() => deferIssueEdit(externalLink, integration, ["state"]),
);
diff --git a/apps/api/src/plugins/github/webhooks/issue-edited.ts b/apps/api/src/plugins/github/webhooks/issue-edited.ts
index 4752ab476..45e12912c 100644
--- a/apps/api/src/plugins/github/webhooks/issue-edited.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-edited.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../utils/deferred-issue-edit";
import { deferIssueEdit } from "../services/deferred-issue-edits";
import { inboundStamp } from "../../github/utils/sync-echo";
import { publishEvent } from "../../../events";
@@ -237,6 +238,10 @@ export async function handleIssueEdited(payload: IssueEditedPayload) {
return;
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() =>
deferIssueEdit(externalLink, integration, [
diff --git a/apps/api/src/plugins/github/webhooks/issue-reopened.ts b/apps/api/src/plugins/github/webhooks/issue-reopened.ts
index 091e7c97f..b7518e337 100644
--- a/apps/api/src/plugins/github/webhooks/issue-reopened.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-reopened.ts
@@ -1,3 +1,4 @@
+import { issueEditScope } from "../utils/deferred-issue-edit";
import { deferIssueEdit } from "../services/deferred-issue-edits";
import type { GitHubConfig } from "../config";
import { getVerifiedInstallationOctokit } from "../utils/github-app";
@@ -162,6 +163,10 @@ export async function handleIssueReopened(payload: IssueReopenedPayload) {
db,
);
},
+ {
+ validate: (binding) =>
+ issueEditScope(binding) === issueEditScope(integration),
+ },
),
() => deferIssueEdit(externalLink, integration, ["state"]),
);
diff --git a/tests/api-integration/deferred-issue-edits.test.ts b/tests/api-integration/deferred-issue-edits.test.ts
index 22cbe3ac6..392672fc7 100644
--- a/tests/api-integration/deferred-issue-edits.test.ts
+++ b/tests/api-integration/deferred-issue-edits.test.ts
@@ -1354,3 +1354,66 @@ it("retains every captured uncertain intent when the corrective provider write f
expect(intent.cancelled).not.toBe(true);
}
});
+
+it.each(
+ providerFields.flatMap((entry) =>
+ ["rebound", "disabled", "credentials"].map((change) => ({
+ ...entry,
+ change,
+ })),
+ ),
+)(
+ "guards the $provider $field confirmation after its integration is $change",
+ async ({ provider, field, change }) => {
+ const { task, integration, link } = await seed(provider);
+ const version = "2026-09-30T00:00:03Z";
+ const before = field === "state" ? "closed" : "A";
+ const after = field === "state" ? "open" : "B";
+ const column = field === "state" ? "status" : field;
+ await db
+ .update(schema.taskTable)
+ .set({ [column]: field === "state" ? "done" : before })
+ .where(eq(schema.taskTable.id, task.id));
+ await db
+ .update(schema.externalLinkTable)
+ .set({
+ metadata: JSON.stringify({
+ lastSync: {
+ [field]: inboundStamp(undefined, before, provider, version),
+ },
+ }),
+ })
+ .where(eq(schema.externalLinkTable.id, link.id));
+ m.read.mockImplementationOnce(async () => {
+ const config = JSON.parse(integration.config);
+ await db
+ .update(schema.integrationTable)
+ .set(
+ change === "disabled"
+ ? { isActive: false }
+ : {
+ config: JSON.stringify({
+ ...config,
+ ...(change === "rebound"
+ ? { repositoryName: "other" }
+ : { accessToken: "new-fake-token" }),
+ }),
+ },
+ )
+ .where(eq(schema.integrationTable.id, integration.id));
+ return {
+ title: field === "title" ? after : "A",
+ body: field === "description" ? after : "A",
+ state: field === "state" ? after : "closed",
+ updated_at: version,
+ };
+ });
+ await deliverField(provider, field, after, version, integration.id);
+ const value = change === "credentials" ? after : before;
+ expect((await current(task.id))?.[column]).toBe(
+ field === "state" ? (value === "closed" ? "done" : "to-do") : value,
+ );
+ expect(m.read).toHaveBeenCalledOnce();
+ if (change !== "credentials") expect(publishEvent).not.toHaveBeenCalled();
+ },
+);