Vision
I envision a login/signup-system, where the user enters his/her email, and receives an email with a link to sign in. The user clicks the link, and is automatically signed in (confirming the email address in the process).
This would be a form of passwordless authentication.
Problem
The problem I see with this approach, is that a link will send a GET request - but this GET request will change the state of the user session (activating it).
GET requests should (according to the HTTP-standard) never have side-effects. This is something browsers assume as well, which means they might prefetch GET requests to optimize performance/user experience.
Let's say you are using Gmail in the browser. Could it then happen that the browser will prefetch the link in the email?
It would be a huge security problem if simply opening the email was enough to be signed in to the site.
What I have considered
Using JavaScript on the landing page to send a POST request
My gut feeling tells me that, even though HTML/CSS/JavaScript from a link could be prefetched, none of this code (especially the JavaScript) will be run before the browser explicitly opens the link.
This should mean that if the user session is somehow activated using JavaScript (by sending a POST request to the backend), it should be safe to use a GET request to get to this page (as a link in the email).
Am I right by assuming this?
Is it bad practice to do it this way?
Using a HTML form in the email body
Another option would be to place a form in the email, which would allow for a POST request from the email directly.
It seems, however - that several email clients will block form submissions from within emails. Email clients that that allow form submissions tend to warn the user that the email is likely malicious. It seems this is not really a good solution.