Skip to content

Email for professionals and teams

fix(security): skip the Gravatar lookup for spam and trash senders (#220)

Hieu Nguyen (Jack)7f5057e9867e
diff --git a/src/lib/contacts/service.ts b/src/lib/contacts/service.ts
index 35d5a20..d3c64a7 100644
--- a/src/lib/contacts/service.ts
+++ b/src/lib/contacts/service.ts
@@ -45,7 +45,7 @@ export async function upsertContactFromAddress(env: CloudflareEnv, input: Contac
source: input.source,
lastSeenAt: now,
}).onConflictDoNothing(); // Two messages from a new sender can be processed at once.
- const avatarKey = await importGravatarAvatar(env, input.userId, email);
+ const avatarKey = input.lookupAvatar === false ? null : await importGravatarAvatar(env, input.userId, email);
if (avatarKey) {
await db.update(contacts).set({ avatarKey }).where(eq(contacts.id, id));
}
diff --git a/src/lib/contacts/types.d.ts b/src/lib/contacts/types.d.ts
index 25fe701..151ee9c 100644
--- a/src/lib/contacts/types.d.ts
+++ b/src/lib/contacts/types.d.ts
@@ -7,6 +7,8 @@ export type ContactInput = {
userId: string;
address: string;
source: ContactSource;
+ /** False skips the Gravatar lookup, which tells a third party that this address mailed us. */
+ lookupAvatar?: boolean;
};
export type BlockContactInput = {
diff --git a/src/lib/email/inbound.ts b/src/lib/email/inbound.ts
index cf3fc98..1ed367a 100644
--- a/src/lib/email/inbound.ts
+++ b/src/lib/email/inbound.ts
@@ -162,6 +162,8 @@ export async function processInboundMessage(
userId: decision.mailbox.userId,
address: fromAddr,
source: "inbound",
+ // Spam senders are strangers at best; do not announce them to Gravatar.
+ lookupAvatar: status !== "spam" && status !== "trash",
}).catch((error) => {
console.error(`Contact upsert failed for ${messageId}`, error);
return null;