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(telegram): redact sensitive config, avoid re-enabling, and skip no-op updates

Tinf3debeb4512c
diff --git a/apps/api/src/telegram-integration/controllers/telegram-controller.ts b/apps/api/src/telegram-integration/controllers/telegram-controller.ts
index a20aa3f08..f202fb0eb 100644
--- a/apps/api/src/telegram-integration/controllers/telegram-controller.ts
+++ b/apps/api/src/telegram-integration/controllers/telegram-controller.ts
@@ -64,8 +64,15 @@ function maskBotToken(value: string): string {
function sanitizeTelegramConfigForLog(rawConfig: string): string {
try {
const parsed = JSON.parse(rawConfig) as Record<string, unknown>;
- if ("botToken" in parsed) {
- parsed.botToken = "[REDACTED]";
+ for (const key of [
+ "botToken",
+ "chatId",
+ "threadId",
+ "chatLabel",
+ ] as const) {
+ if (key in parsed) {
+ parsed[key] = "[REDACTED]";
+ }
}
return JSON.stringify(parsed);
} catch {
diff --git a/apps/api/src/telegram-integration/index.ts b/apps/api/src/telegram-integration/index.ts
index 6ce8d1400..73f3d2368 100644
--- a/apps/api/src/telegram-integration/index.ts
+++ b/apps/api/src/telegram-integration/index.ts
@@ -18,6 +18,7 @@ import {
getTelegramIntegration,
parseTelegramIntegrationConfig,
telegramIntegrationPatchBodySchema,
+ toResponse,
} from "./controllers/telegram-controller";
function safePublishIntegrationEvent(
@@ -133,6 +134,7 @@ telegramIntegration
eq(integrationTable.projectId, projectId),
eq(integrationTable.type, "telegram"),
),
+ columns: { id: true },
});
await db
@@ -147,7 +149,6 @@ telegramIntegration
target: [integrationTable.projectId, integrationTable.type],
set: {
config: JSON.stringify(config),
- isActive: true,
updatedAt: new Date(),
},
});
@@ -214,6 +215,18 @@ telegramIntegration
buildNextTelegramConfigFromPatch(body, currentConfig),
);
+ const resolvedIsActive =
+ body.isActive !== undefined
+ ? body.isActive
+ : (existing.isActive ?? true);
+
+ if (
+ JSON.stringify(currentConfig) === JSON.stringify(nextConfig) &&
+ resolvedIsActive === (existing.isActive ?? true)
+ ) {
+ return c.json(toResponse(existing));
+ }
+
const validation = validateTelegramConfig(nextConfig);
if (!validation.valid) {
throw new HTTPException(400, {
@@ -225,10 +238,7 @@ telegramIntegration
.update(integrationTable)
.set({
config: JSON.stringify(nextConfig),
- isActive:
- body.isActive !== undefined
- ? body.isActive
- : (existing.isActive ?? true),
+ isActive: resolvedIsActive,
updatedAt: new Date(),
})
.where(eq(integrationTable.id, existing.id));