diff --git a/server/routes/api/notifications/notifications.ts b/server/routes/api/notifications/notifications.ts index 587fe446cd..9a1d5c5785 100644 --- a/server/routes/api/notifications/notifications.ts +++ b/server/routes/api/notifications/notifications.ts @@ -57,8 +57,19 @@ router.get( "notifications.unsubscribe", validate(T.NotificationsUnsubscribeSchema), transaction(), - handleUnsubscribe + async (ctx: APIContext) => { + const { follow } = ctx.input.query; + + // The link in the email does not include the follow query param, this + // is to help prevent anti-virus, and email clients from pre-fetching the link + if (!follow) { + return ctx.redirectOnClient(ctx.request.href + "&follow=true"); + } + + return handleUnsubscribe(ctx); + } ); + router.post( "notifications.unsubscribe", validate(T.NotificationsUnsubscribeSchema), diff --git a/server/routes/api/notifications/schema.ts b/server/routes/api/notifications/schema.ts index 2e4c66f48c..ecc8dfd352 100644 --- a/server/routes/api/notifications/schema.ts +++ b/server/routes/api/notifications/schema.ts @@ -30,6 +30,7 @@ export const NotificationsUnsubscribeSchema = BaseSchema.extend({ eventType: z.nativeEnum(NotificationEventType).optional(), }), query: z.object({ + follow: z.string().default(""), userId: z.string().uuid().optional(), token: z.string().optional(), eventType: z.nativeEnum(NotificationEventType).optional(), diff --git a/server/routes/api/subscriptions/schema.ts b/server/routes/api/subscriptions/schema.ts index f76cb3d941..e4624ad1eb 100644 --- a/server/routes/api/subscriptions/schema.ts +++ b/server/routes/api/subscriptions/schema.ts @@ -47,6 +47,7 @@ export type SubscriptionsDeleteReq = z.infer; export const SubscriptionsDeleteTokenSchema = BaseSchema.extend({ query: z.object({ + follow: z.string().default(""), userId: z.string().uuid(), documentId: z.string().uuid(), token: z.string(), diff --git a/server/routes/api/subscriptions/subscriptions.ts b/server/routes/api/subscriptions/subscriptions.ts index caa96b5703..350098a993 100644 --- a/server/routes/api/subscriptions/subscriptions.ts +++ b/server/routes/api/subscriptions/subscriptions.ts @@ -150,7 +150,13 @@ router.get( transaction(), async (ctx: APIContext) => { const { transaction } = ctx.state; - const { userId, documentId, token } = ctx.input.query; + const { follow, userId, documentId, token } = ctx.input.query; + + // The link in the email does not include the follow query param, this + // is to help prevent anti-virus, and email clients from pre-fetching the link + if (!follow) { + return ctx.redirectOnClient(ctx.request.href + "&follow=true"); + } const unsubscribeToken = SubscriptionHelper.unsubscribeToken( userId,