fix: Add prevention of auto-following unsubscribe links in emails

This commit is contained in:
Tom Moor committed 2025-03-20 23:56:14 -04:00
1 parent f369c2f8bf
commit 8367bc76cd
4 files changed
+21 -2

No files matched your search

@@ -57,8 +57,19 @@ router.get(
"notifications.unsubscribe",
validate(T.NotificationsUnsubscribeSchema),
transaction(),
handleUnsubscribe
async (ctx: APIContext<T.NotificationsUnsubscribeReq>) => {
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),
@@ -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(),
@@ -47,6 +47,7 @@ export type SubscriptionsDeleteReq = z.infer<typeof SubscriptionsDeleteSchema>;
export const SubscriptionsDeleteTokenSchema = BaseSchema.extend({
query: z.object({
follow: z.string().default(""),
userId: z.string().uuid(),
documentId: z.string().uuid(),
token: z.string(),
@@ -150,7 +150,13 @@ router.get(
transaction(),
async (ctx: APIContext<T.SubscriptionsDeleteTokenReq>) => {
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,