summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-05-27 13:37:40 (GMT)
committerGitHub <noreply@github.com>2020-05-27 13:37:40 (GMT)
commit75635c6095bcfbb9fccc239115d3d03ae20a307f (patch)
tree002635c5771d551f74dd65711a014661c4d99dbe /Lib/test
parent5594c07d97cc56ec7fabc66c6a5c644d3b809612 (diff)
downloadcpython-75635c6095bcfbb9fccc239115d3d03ae20a307f.zip
cpython-75635c6095bcfbb9fccc239115d3d03ae20a307f.tar.gz
cpython-75635c6095bcfbb9fccc239115d3d03ae20a307f.tar.bz2
bpo-39073: validate Address parts to disallow CRLF (GH-19007)
Disallow CR or LF in email.headerregistry.Address arguments to guard against header injection attacks. (cherry picked from commit 614f17211c5fc0e5b828be1d3320661d1038fe8f) Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_email/test_headerregistry.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py
index 8d89c5d..a43d51f 100644
--- a/Lib/test/test_email/test_headerregistry.py
+++ b/Lib/test/test_email/test_headerregistry.py
@@ -1436,6 +1436,25 @@ class TestAddressAndGroup(TestEmailBase):
# with self.assertRaises(ValueError):
# Address('foo', 'wők', 'example.com')
+ def test_crlf_in_constructor_args_raises(self):
+ cases = (
+ dict(display_name='foo\r'),
+ dict(display_name='foo\n'),
+ dict(display_name='foo\r\n'),
+ dict(domain='example.com\r'),
+ dict(domain='example.com\n'),
+ dict(domain='example.com\r\n'),
+ dict(username='wok\r'),
+ dict(username='wok\n'),
+ dict(username='wok\r\n'),
+ dict(addr_spec='wok@example.com\r'),
+ dict(addr_spec='wok@example.com\n'),
+ dict(addr_spec='wok@example.com\r\n')
+ )
+ for kwargs in cases:
+ with self.subTest(kwargs=kwargs), self.assertRaisesRegex(ValueError, "invalid arguments"):
+ Address(**kwargs)
+
def test_non_ascii_username_in_addr_spec_raises(self):
with self.assertRaises(ValueError):
Address('foo', addr_spec='wők@example.com')