validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

IsEmail() consider invisible character in email as valid

Open Scarus opened this issue 3 years ago • 10 comments

Description

One of our users entered an email address like the following: "​[email protected]" It contains an invisible character at the beginning (maybe the result of a weird copy/paste ?) (You can make it appear by pasting the string into a web browser console) It resulted in hard to spot problems as you would expect when two seemingly identical strings are in fact not matching.

The email string was validated using these decorators:

    @IsNotEmpty()
    @IsString()
    @IsEmail()
    public email: string;

Expected behavior

IsEmail should deny the validation of the email when it contains an invisible character.

Actual behavior

IsEmail() validate the email containing the invisible character

Scarus avatar Sep 08 '22 14:09 Scarus

@Scarus - can you pls assign this issue to me? I would like to work on it

meeraj257 avatar Sep 21 '22 03:09 meeraj257

Feel free to open a PR for this, @meeraj257 there's no need to be assigned to this

WikiRik avatar Sep 21 '22 21:09 WikiRik

Thanks @WikiRik . I will raise a PR soon in 1-2 days. Wanted to make sure others also not work on the same.

meeraj257 avatar Sep 23 '22 00:09 meeraj257

#2049 - Link to PR for this issue

meeraj257 avatar Sep 27 '22 17:09 meeraj257

@WikiRik - PR raised. Pls review the PR.

meeraj257 avatar Sep 27 '22 17:09 meeraj257

@Scarus could you assign this issue to me? Would be happy to work on it!

ashishbalti4 avatar Oct 15 '22 13:10 ashishbalti4

@Scarus could you assign this issue to me? Would be happy to work on it!

PR #2049 has already been opened to fix this issue

WikiRik avatar Oct 15 '22 13:10 WikiRik

@tux-tn - i saw your comments. The email RFC is broad and includes the whole range. I think having invisible characters in strings in general is very confusing and does cause issues like when you use it to send emails by typing it or you have blocked or allowed lists in applications. So i think its ok to not allow certain subset . we can add a flag to override this default behavior if anyone needs emails with invisible characters to be allowed. I think this change is actually beneficial and not taking away any useful functionality. Like to see inputs from issue owner @Scarus

meeraj257 avatar Oct 19 '22 14:10 meeraj257

@meeraj257 it would be good to put this comment in the PR as well

WikiRik avatar Oct 19 '22 15:10 WikiRik

Hi all, any news regarding this issue? I had to deal with a bug on our application due to the invisible character passing the email validation...

BUONJG avatar Apr 10 '24 08:04 BUONJG