Skip to content

Commit

Permalink
[user_accounts] Revert aces#2018 - Sanitization before validation of …
Browse files Browse the repository at this point in the history
…email falsifies validity (aces#8137)

When an email address is entered with invalid characters, the invalid characters are currently stripped before the address is validated, causing the validation to improperly pass when it should fail for email addresses such as "[email protected]>". The sanitation pass turns that into "[email protected]" before it's validated, which returns "true" despite the address entered being invalid.

This also removes an old check for < > and " because the new check offers a clearer error message and covers a broader range of characters we don't want in emails (because of escaping issues).
  • Loading branch information
ridz1208 authored and cmadjar committed Aug 10, 2022
1 parent 9a72295 commit 6c5718b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/user_accounts/php/edit_user.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,13 @@ class Edit_User extends \NDB_Form
*/
private function _getEmailError(\Database $DB, string $email): ?string
{
// remove illegal characters
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (preg_match('/(<|>|"|&)/', $email)) {
// Although some of these characters are legal in emails, due to the
// current HTML escaping method, it is better to reject email
// addresses containing them
return 'Email address can not contain any the following '.
'characters: <, >, & and "';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
// If email not syntactically valid
return "Invalid email address";
}
Expand Down

0 comments on commit 6c5718b

Please sign in to comment.