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(admin): block sync writes through turned-off integration providers

Tindb1358e6c19a
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index c22dab81c..0695b8c62 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -826,12 +826,19 @@ export function createApp() {
notificationPreferences,
);
const searchApi = api.route("/search", search);
- const integrationSyncApi = api.route("/integration-sync", integrationSync);
+ // Turned-off providers: registered before their routes so they run first.
// Inbound provider webhooks are mounted earlier and answer on their own;
// their work is skipped through `activeIntegrationCondition`.
for (const { type } of integrationPlugins) {
api.use(`/${type}-integration/*`, requireIntegrationProviderEnabled(type));
}
+ // Saving sync rules and resuming paused links write through the provider.
+ const syncProvider = requireIntegrationProviderEnabled((c) =>
+ c.req.param("provider"),
+ );
+ api.use("/integration-sync/project/:projectId/:provider", syncProvider);
+ api.use("/integration-sync/project/:projectId/:provider/*", syncProvider);
+ const integrationSyncApi = api.route("/integration-sync", integrationSync);
const githubIntegrationApi = api.route(
"/github-integration",
githubIntegration,
diff --git a/apps/api/src/instance-settings/require-integration-provider-enabled.ts b/apps/api/src/instance-settings/require-integration-provider-enabled.ts
index d19759cf7..5e6bbca8d 100644
--- a/apps/api/src/instance-settings/require-integration-provider-enabled.ts
+++ b/apps/api/src/instance-settings/require-integration-provider-enabled.ts
@@ -8,11 +8,15 @@ const READ_OR_REMOVE = new Set(["GET", "HEAD", "OPTIONS", "DELETE"]);
* While a provider is turned off, projects can still see and remove their
* connection, but can't connect, change, or import through it.
*/
-export function requireIntegrationProviderEnabled(type: string) {
+export function requireIntegrationProviderEnabled(
+ type: string | ((c: Context) => string | undefined),
+) {
return async function requireProviderEnabled(c: Context, next: Next) {
+ if (READ_OR_REMOVE.has(c.req.method)) return next();
+ const provider = typeof type === "string" ? type : type(c);
if (
- !READ_OR_REMOVE.has(c.req.method) &&
- (await getInstanceSettings()).disabledIntegrations.includes(type)
+ provider &&
+ (await getInstanceSettings()).disabledIntegrations.includes(provider)
) {
throw new ApiError(403, {
code: "INTEGRATION_PROVIDER_DISABLED",
diff --git a/tests/api-integration/admin-instance-settings.test.ts b/tests/api-integration/admin-instance-settings.test.ts
index 4255be0bf..d2eb25117 100644
--- a/tests/api-integration/admin-instance-settings.test.ts
+++ b/tests/api-integration/admin-instance-settings.test.ts
@@ -575,5 +575,41 @@ describe("integration providers", () => {
},
);
expect(discord.status).not.toBe(403);
+
+ // Sync rules and paused-link resumes write through the provider too.
+ await admin.api("/settings", {
+ method: "PATCH",
+ body: { disabledIntegrations: ["slack", "github"] },
+ });
+ const sync = (method: string, suffix = "") =>
+ app.request(
+ `/api/integration-sync/project/${project.id}/github${suffix}`,
+ {
+ method,
+ headers: { ...json, cookie: admin.cookies },
+ body: method === "GET" ? undefined : JSON.stringify({}),
+ },
+ );
+ for (const [method, suffix] of [
+ ["PATCH", ""],
+ ["POST", "/preview"],
+ ["POST", "/links/link-1/resume"],
+ ] as const) {
+ const response = await sync(method, suffix);
+ expect(response.status, `${method} ${suffix}`).toBe(403);
+ expect(await readErrorBody(response)).toMatchObject({
+ code: "INTEGRATION_PROVIDER_DISABLED",
+ });
+ }
+ expect((await sync("GET")).status).not.toBe(403);
+ const gitea = await app.request(
+ `/api/integration-sync/project/${project.id}/gitea`,
+ {
+ method: "PATCH",
+ headers: { ...json, cookie: admin.cookies },
+ body: JSON.stringify({}),
+ },
+ );
+ expect(gitea.status).not.toBe(403);
});
});