Preface: I'm not a web developer, I'm just trying to learn as I go while making my first website.
I stumbled on an engineering problem in regards to unsubscribing from newsletter. I thought it would be a good idea to use a get method with a parameter like this:
/unsubscribe=qwerty@qwerty.com
Then I went ahead and implemented it in javascript:
app.get('/unsubscribe:subEmail', async (req, res) => {
subEmail = req.params.subEmail.substring(1);
let subscriber = await Subscriber.findOne({ email: subEmail })
if(subscriber == null){
res.send('subscriber doesnt exist')
return;
}
await subscriber.delete()
res.redirect('/')
})
But, then it occurred to me; how do I make sure the email provided does not belong to another subscriber?
Question: What are the good engineering solutions used to prevent abusing this?