Repository navigation
Conversation
With strict=True, the 64-octet local part limit (RFC 5321 4.5.3.1.1) was checked against the unquoted, unescaped local part. For a quoted-string local part, the local part that is returned (and that would be transmitted) also includes the surrounding quotes and any backslash escapes that are still needed, so addresses whose local part was up to twice the limit were accepted, e.g. 32 escaped quotes give a 66-character local part. Check the length again after the local part is re-quoted.
Author
|
Fair enough, closing this. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #197.
Problem
strict=Truechecks the local part length (RFC 5321 4.5.3.1.1, 64 octets) on the unquoted, unescaped local part. When the local part is a quoted string, thelocal_partandnormalizedvalues that come back (which are what would be transmitted) also contain the two quotes and any backslash escapes that are still needed. As a result,strict=True, allow_quoted_local=Trueaccepted local parts of up to about twice the limit, for example'"' + '\\"' * 32 + '"@example.com'(a 66-character local part).Change
In
validate_email_local_part, after a quoted-string local part is re-quoted and re-escaped, check the length again understrict. The error message is the same as the existing one ("The email address is too long before the @-sign (N character(s) too many).")."\a\a...\a"with 64as normalizes to an unquoted 64-character local part and is still accepted. This matches RFC 5321 4.1.2, which says all quoted forms are equivalent.validate_emailcalls the same function, so the check also applies to the normalized form.Tests
test_email_invalid_syntax_strict_quoted: three addresses that pass withoutstrictand are rejected withstrict=True, each with an exact error message. They cover the quotes added because of a space, escaped quotes, and an escaped backslash.test_email_valid_strict_quoted: a quoted local part that is exactly 64 characters including the quotes, and an over-escaped input that normalizes to 64 characters. Both are still accepted.The three new invalid cases fail on main and pass with this change.
pytest -k "not network": 348 passed.flake8 --ignore=E501,E126,W503 email_validator tests: clean.