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(notifications): encode non-ASCII ntfy titles

Justin Willhite7ad986a5bc58
diff --git a/apps/api/src/notification-preferences/delivery.ts b/apps/api/src/notification-preferences/delivery.ts
index 89f3d7502..42362feb7 100644
--- a/apps/api/src/notification-preferences/delivery.ts
+++ b/apps/api/src/notification-preferences/delivery.ts
@@ -275,7 +275,10 @@ async function sendNtfyNotification(input: {
headers: {
...(input.token ? { Authorization: `Bearer ${input.token}` } : {}),
...(input.clickUrl ? { Click: input.clickUrl } : {}),
- Title: input.title,
+ // fetch rejects header values outside Latin-1, so send non-ASCII titles RFC 2047 encoded; ntfy decodes them.
+ Title: /^[\x20-\x7e]*$/.test(input.title)
+ ? input.title
+ : `=?UTF-8?B?${Buffer.from(input.title).toString("base64")}?=`,
},
body: input.body,
},
diff --git a/tests/api-integration/notification-access.test.ts b/tests/api-integration/notification-access.test.ts
index b5924a585..cc84804ad 100644
--- a/tests/api-integration/notification-access.test.ts
+++ b/tests/api-integration/notification-access.test.ts
@@ -354,4 +354,42 @@ describe("notification recipient boundaries", () => {
expect(logged).not.toContain(secret);
expect(logged).toContain("network");
});
+
+ it("sends ntfy titles with non-Latin-1 characters as a valid header", async () => {
+ const { actor, member, task } = await fixture();
+ const [notification] = await db
+ .insert(schema.notificationTable)
+ .values({
+ userId: member.user.id,
+ resourceType: "task",
+ resourceId: task.id,
+ type: "task_comment",
+ title: "日本語のタスク",
+ content: "body",
+ })
+ .returning();
+ await db.insert(schema.userNotificationPreferenceTable).values({
+ userId: member.user.id,
+ ntfyEnabled: true,
+ ntfyServerUrl: "http://127.0.0.1",
+ ntfyTopic: "topic",
+ });
+ await db.insert(schema.userNotificationWorkspaceRuleTable).values({
+ userId: member.user.id,
+ workspaceId: actor.workspace.id,
+ ntfyEnabled: true,
+ });
+ vi.stubEnv("KANEO_ALLOW_PRIVATE_WEBHOOK_DESTINATIONS", "true");
+ const fetchMock = vi.fn().mockResolvedValue(new Response(null));
+ vi.stubGlobal("fetch", fetchMock);
+ const log = vi.spyOn(console, "error").mockImplementation(() => {});
+ await deliverNotification(notification.id);
+ expect(log).not.toHaveBeenCalled();
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ const title = new Headers(fetchMock.mock.calls[0][1].headers).get("Title");
+ const [, encoded] = title?.match(/^=\?UTF-8\?B\?(.+)\?=$/) ?? [];
+ expect(Buffer.from(encoded ?? "", "base64").toString()).toBe(
+ "日本語のタスク",
+ );
+ });
});