Menu

Our unsubscribe link is a 64 character HMAC, and the GET that mail scanners follow is built to do nothing
📰

Our unsubscribe link is a 64 character HMAC, and the GET that mail scanners follow is built to do nothing

DEV Community: typescript·Daniel Pertu·1 day ago
#IrKfecaT
#devtotypescript#devto#dev#unsubscribe#token
Reading 0:00
15s threshold

PubTrivia sends product update emails to venues who opted in. Those emails need an unsubscribe link that works for a person who is not signed in, who may be reading in a mail client that will never show them a browser, and whose message has already been opened and refetched by two or three security scanners before they see it.

That is four constraints, and they decide the whole design. Here is what we ended up with, and the live endpoints you can poke at while you read.

The token

The authorisation is an HMAC of the user id, and nothing else:

function sign ( userId : string , key : string ) : string { return createHmac ( 'sha256' , key ) . update ( `unsubscribe:${userId}` ) . digest ( 'hex' ) }

Enter fullscreen mode

Exit fullscreen mode

64 hex characters.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.