class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

fix: IsEmail() consider invisible character in email as valid

Open Scarus opened this issue 3 years ago • 1 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 May 04 '22 16:05 Scarus

The @IsEmail() is responsible for checking if a string is an email or not. Email pattern is like this *@*.* and as long as it has the pattern, It doesn't matter what kind of characters are instead of *. I think it would be better to have another type of decorator to check those cases. (If class-validator already doesn't have)

vader-sama avatar Jun 23 '22 20:06 vader-sama

@vader-sama It seems to me the validation pattern for email is far more complex than *@*.*. If I'm not wrong the code is here: https://github.com/validatorjs/validator.js/blob/master/src/lib/isEmail.js

I suppose the invisible character reported by @Scarus is allowed by the validator but I believe it shouldn't.

Perhaps it is more an issue to report on the validatorjs repository...

BUONJG avatar Aug 30 '22 14:08 BUONJG

Please close this issue and open a new one in validator.js, @Scarus :)

braaar avatar Aug 30 '22 15:08 braaar

New Issue submitted in https://github.com/validatorjs/validator.js Closing this one

Scarus avatar Sep 08 '22 14:09 Scarus

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Oct 09 '22 00:10 github-actions[bot]