Activation links should be idempotent so they're not consumed by crawlers or accidental clicks #17330
-
We frequently have issues with sites that have public registrations. Users complain that the activation link they received doesn't work, instead they get a HTTP 400 Bad Request error response. Usually, this means that the activation code has already been consumed. The problem is that those links are not idempotent. They only work once and throw an error when they're visited again. This only happens with activation links like this, it doesn't happen with the password reset flow:
This behavior is way too error-prone. Users may have clicked the link already and then closed the tab, maybe even before the page fully loaded, and then forgot about it. But this can even happen without any user interaction. Some email providers and antivirus software will follow links to scan for malware, which also consumes the activation link. Any plugin or email app feature that shows a link preview will also break this workflow. And we all remember that time Microsoft decided to send all links in all emails from Outlook to Bing for indexing … A good solution would be to make the email verification links idempotent to make them more resilient. For example:
Broader view: I've only noticed this in the context of verification links, but I'm not sure if this also affects any other links generated by Craft. User impersonation also does this, though I don't think it's an issue here. Any fix should probably address this problem in a general way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I’m not able to reproduce that behavior. Activation links show a Set Password template initially, and the verification code isn’t actually removed from the user until they set their password. What am I missing? |
Beta Was this translation helpful? Give feedback.
-
This has been addressed for Craft 5.8: #17392 |
Beta Was this translation helpful? Give feedback.
This has been addressed for Craft 5.8: #17392