There is another question with similar title: Unsubscribe safely however my question addresses completely another issue.
I am trying to set up a notification system in the website, that will send emails to users based on different events on the webiste, it might be e.g. receiving on-site message from another user, someone purchasing your product, leaving a feedback etc. - there are a lot of things that might trigger a notification. Users from their account settings can choose for which exact events they want to receive an email.
I was reading email best practices from mailgun https://documentation.mailgun.com/best_practices.html#unsubscribe-handling
and I learnt that
It is important to give you recipients the ability to unsubscribe from emails. First, it is required by the CAN-Spam Act. Second, if you don’t give them this option, they are more likely to click on the spam complaint button, which will cause more harm than allowing them to unsubscribe. Finally, many ESPs look for unsubscribe links and are more likely to filter your email if they don’t have them.
Also, from gmail guidelines about Unsubscribing https://support.google.com/mail/answer/81126?hl=en
A user must be able to unsubscribe from your mailing list through one of the following means:
A prominent link in the body of an email leading users to a page confirming his or her unsubscription (no input from the user, other than confirmation, should be required). By replying to your email with an unsubscribe request.
So, I do want to have the unsubscribe option in the email. I would not really prefer to use the second option (By replying to your email) as it might have some technical difficulties (e.g. I have to the notification type in response email, have to check the email for inbox regularly and maybe smth else I have not thought of). I'm thinking of having a unsubscribe link in the email and because their notification settings can be changed only after they are logged in, it contradicts with gmail's
no input from the user, other than confirmation, should be required point.
So, it looks like I am left with some "public" url for changing their notification settings. From as I read and used to handle similar cases - e.g. when confirming the email or password recovery, I am sending an email that in url contains only randomly generated hash(sha512), NOT in any way revealing the user info, which expires in less than 1 hour(I used to put 15 mins).
Now, in case of unsubscribe link, even though I include random hash (and maybe the notification type id as well), that is tied to the user in the database, because its public, if it the email/link accidentally shared or posted somewhere, someone else can edit that user's notification preferences. On the other hand, generating random hash with each notification and saving in the db, also expiring them after some time sounds overkill for me, also considering that as it expires, if the user clicks on unsubscribe link in old email, it will not work.
I could not find any useful information out there, so I am seeking some advice on how to correctly and securely approach user unsubscribing in general and specifically in cases similar to mine. Any help is very much appreciated.
JWT, looks like a cool thing.