+25
-0
lines changedFilter options
+25
-0
lines changed Original file line number Diff line number Diff line change
@@ -31,6 +31,11 @@ def __init__(self, display_name='', username='', domain='', addr_spec=None):
31
31
without any Content Transfer Encoding.
32
32
33
33
"""
34
+
35
+
inputs = ''.join(filter(None, (display_name, username, domain, addr_spec)))
36
+
if '\r' in inputs or '\n' in inputs:
37
+
raise ValueError("invalid arguments; address parts cannot contain CR or LF")
38
+
34
39
# This clause with its potential 'raise' may only happen when an
35
40
# application program creates an Address object using an addr_spec
36
41
# keyword. The email library code itself must always supply username
Original file line number Diff line number Diff line change
@@ -1437,6 +1437,25 @@ def test_il8n(self):
1437
1437
# with self.assertRaises(ValueError):
1438
1438
# Address('foo', 'wők', 'example.com')
1439
1439
1440
+
def test_crlf_in_constructor_args_raises(self):
1441
+
cases = (
1442
+
dict(display_name='foo\r'),
1443
+
dict(display_name='foo\n'),
1444
+
dict(display_name='foo\r\n'),
1445
+
dict(domain='example.com\r'),
1446
+
dict(domain='example.com\n'),
1447
+
dict(domain='example.com\r\n'),
1448
+
dict(username='wok\r'),
1449
+
dict(username='wok\n'),
1450
+
dict(username='wok\r\n'),
1451
+
dict(addr_spec='wok@example.com\r'),
1452
+
dict(addr_spec='wok@example.com\n'),
1453
+
dict(addr_spec='wok@example.com\r\n')
1454
+
)
1455
+
for kwargs in cases:
1456
+
with self.subTest(kwargs=kwargs), self.assertRaisesRegex(ValueError, "invalid arguments"):
1457
+
Address(**kwargs)
1458
+
1440
1459
def test_non_ascii_username_in_addr_spec_raises(self):
1441
1460
with self.assertRaises(ValueError):
1442
1461
Address('foo', addr_spec='wők@example.com')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
+
Disallow CR or LF in email.headerregistry.Address arguments to guard against header injection attacks.
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4