Provide email address verification feature#2481
Conversation
fbf4975 to
7fe6119
Compare
|
I made a bunch of improvements and added a bit of documentation. I think it's now ready to be reviewed, but it's still blocking by #2476 (from which the two first commits come). Also added the "nice to have" improvements that I didn't implement in the first message. |
7fe6119 to
b548a77
Compare
| return false; | ||
| } | ||
|
|
||
| if ($email !== null && $userConfig->mail_login !== $email) { |
There was a problem hiding this comment.
$email != '' would be safer here, especially since it might come from Minz_Request::param('email', '');
There was a problem hiding this comment.
That was on purpose since the email should not be required when force_email_validation is false. But I realize that I should enforce the value if it's true.
| } | ||
|
|
||
| if ($email !== null && $userConfig->mail_login !== $email) { | ||
| $userConfig->mail_login = $email; |
There was a problem hiding this comment.
Somewhere we need to sanitize this user input. Either here or in profileAction().
I suggest looking at https://php.net/filter.filters.validate FILTER_VALIDATE_EMAIL / FILTER_SANITIZE_EMAIL
There was a problem hiding this comment.
I would simply check that the email contains a @. Maybe we can strip the string too. But emails are hard to validate and it's almost always badly done (more here). And I'm not comfortable with that:
In general, this validates e-mail addresses against the syntax in RFC 822, with the exceptions that comments and whitespace folding and dotless domain names are not supported.
I don't understand why they would respect the RFC, but in fact not…
The feature itself is about validating that the address is valid by sending an email so I don't think we have to be too strict.
There was a problem hiding this comment.
That's definitely very odd about dotless domains. The whitespace & comments things is more common. For example, the W3C recommends this for input type=email:
This requirement is a willful violation of RFC 5322, which defines a syntax for e-mail addresses that is simultaneously too strict (before the "@" character), too vague (after the "@" character), and too lax (allowing comments, whitespace characters, and quoted strings in manners unfamiliar to most users) to be of practical use here.
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
There was a problem hiding this comment.
There are still some classes of characters, which should be discarded, and potentially also a min and max length. I think it is dangerous to pass some user input to the backend without any form of sanitization. If you do not like the PHP built-in validation (which I personally think would be reasonable - I an not even sure the rest of the back-end is able to handle what the PHP validation rejects anyway), then at least the sanitize filter FILTER_SANITIZE_EMAIL https://php.net/manual/filter.filters.sanitize
There was a problem hiding this comment.
Ok, I'll take a look to clean at least a bit this param!
There was a problem hiding this comment.
Ah, I did not realise that the HTML5 version does not allow UTF-8 before the @ 😢
There was a problem hiding this comment.
So, it seems that the conclusion is to use the PHPMailer's pcre8 option as @Frenzie suggested higher up
There was a problem hiding this comment.
Thanks for digging into the problem! (I was finishing my holidays :)) I didn't thought that PHPMailer could have a verification function (sounds obvious now!) I'll try to finish this tomorrow 👍
There was a problem hiding this comment.
It looks like none of the patterns allow internationalized email addresses (not even pcre8). I'm also very surprised that Firefox or Thunderbird don't allow UTF-8 before the @ either… Is there any server or client that fully support UTF-8 addresses?!
I found that PHPMailer provides a punyencodeAddress function which convert only the domain, that's a start. So I'll convert the address to punycode first and validate the address against this value. Then I can either store the value as punycode (but I'll have to transform it again when displaying the address) or store the utf-8 version (easier, and it should be ok since PHPMailer transforms all the addresses before sending the email)
There was a problem hiding this comment.
Is there any server or client that fully support UTF-8 addresses?!
Sure, Microsoft has announced support, this one does http://www.postfix.org/SMTPUTF8_README.html
There's an incomplete list on Wikipedia:
https://en.wikipedia.org/wiki/Extended_SMTP#SMTPUTF8
Edit: to be clear, that list is from like 4 years ago and even then I doubt it was complete.
I reuse the `mail_login` from the configuration. I'm not sure if it's useful today (I would say it was used when Persona login was available). A good improvement would be to rename `mail_login` into `email` so it would be more intuitive to use.
This commit only adds a configuration item.
ded76ef to
d037d9a
Compare
|
Just to let you know @Alkarex, I saw you merged |
|
@marienfressinaud I just used GitHub's built-in tool to resolve the conflict :-) |
|
Btw, perhaps you already know but I recently discovered that on GitHub you can do this: # assuming your own fork is origin and the one here is upstream
git fetch upstream pull/2481/head
git checkout FETCH_HEAD |
|
That's interesting and I strongly agree with some of your arguments. In the mean time, I consider my branches as my personal workspaces and nobody should base their work on it nor modify them. In this context, force-push should not be a problem. I would not recommend to test different work-in-progress branches at the same time neither, but I can understand that can be useful. I'm not a huge fan of squash because you lose how the feature has been constructed. I always try to build my PRs logically and they are reviewable commit by commit. I personally prefer a merge with no fast-forward to keep the history. It can also help a lot to understand why and how a bug got introduced. In the mean time, GitHub is definitely not adapted to this workflow: as you said, comments are lost, it's difficult to see the last changes, commits are not ordered correctly in the "Commits" tab, etc. Considering that, I'll try an "in-between": I'll commit my fixes with |
|
It is not a big deal in any case :-) A bit more feedbacks: |
|
I think it's all good now! |
|
And still have the following error, preventing any e-mail from being sent: P.S.: No difference between |
|
It is because PHPMailer calls PHP's FILTER_VALIDATE_EMAIL which does not accept |
|
I suggest adding: PHPMailer::$validator = 'pcre8'; |
|
With the syntax fix, and the validator fix, it should be good for me. |
Co-Authored-By: Alexandre Alapetite <[email protected]>
|
I used |
|
Uh, I see on fediverse that FreshRSS has been updated, so i the update from web admin interface has alway !
I recommend you to use php empty function instead strongly typed equality : $email_not_verified = !empty(FreshRSS_Context::$user_conf->email_validation_token);Check https://www.php.net/manual/en/function.empty.php More safe in context of checking config that can be from very old version of app my instance running without update issue from many years (4-5years I think) At this time, I'm happy to be a Developper or I will not hase solve my issue without help ^^. Best regards |
|
@Purexo Yes, this line is indeed bad, especially the strict inequality. Could you please send a pull request to fix it? I have not checked much the e-mail flow ( ping @marienfressinaud ), but couldn't you log with your normal username? Please open another issue if that was not the case. |
|
I confirm that the |
|
Side note about |
|
When some data comes from somewhere that is not fully controlled, the code should allow for some typical variations. In this case, I do not think it makes sense to strictly test for an empty string and fail for the other nullable values. In this case, I would argue for FreshRSS/lib/Minz/Configuration.php Lines 139 to 163 in 0320877 (Which I think we should remove at some point in favour of native code, but that is another story :-)) |
I was not able to connect with my username nor email.
I've looked into the Yes I've update with zip (available in web-admin interface), it work well from many years and really convenient. I can make a fast PR from github if you wan't. Should I checkout from |
|
@Purexo Yes please, /dev branch 👍 |
This PR adds the support for email address verification.
It is based on #2476 (so this one needs to be merged first) and better reviewed commit by commit.
Closes #2469
Nice to have
These are improvements that are not "necessary" but could be nice to have. I added the reason why I didn't implement these in parenthesis:
mail_loginintoemailso it's more intuitive (need to migrate current configuration)force_email_validationto the CLI (useful?)Depending on your feedback, I can implement them in this PR, in other PRs, or not at all ;)
Basic workflow
An email field is added to the profile page.
If the
force_email_validationboolean is set totrue: