{"id":1059,"cve":"CVE-2024-6923","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2024-6923\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":5.5,"published":"2024-08-01","owasp":"A03 Injection","odc":"Checking","cdc":"Incorrect Check","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Information Disclosure","summary":"Email module in CPython allows header injection due to improper newline quoting.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2024-6923\/","description":"There is a MEDIUM severity vulnerability affecting CPython.\n\nThe \nemail module didn\u2019t properly quote newlines for email headers when \nserializing an email message allowing for header injection when an email\n is serialized.","solution":"Upgrade to CPython version 3.10.5 or later, where this issue is addressed.","affected_component":"Python","fixed_by_upgrading":true,"vulnerable_code":"import email\nfrom email.message import EmailMessage\n\nmsg = EmailMessage()\nmsg['Subject'] = 'Test Email'\nmsg['From'] = 'sender@example.com'\nmsg['To'] = 'recipient@example.com'\n\nmsg['X-Custom-Header'] = 'Value with newline\\nInjected Header: value'\n\nserialized_msg = msg.as_string()\n\nprint(serialized_msg)","patched_code":"import email\nfrom email.message import EmailMessage\nimport re\n\ndef sanitize_email_headers(msg):\n    for header, value in msg.items():\n        if '\\n' in value or '\\r' in value:\n            msg[header] = re.sub(r'[\\r\\n]', '', value)\n    return msg\n\nmsg = EmailMessage()\nmsg['Subject'] = 'Test Email'\nmsg['From'] = 'sender@example.com'\nmsg['To'] = 'recipient@example.com'\nmsg['X-Custom-Header'] = 'Value with newline\\nInjected Header: value'\n\nmsg = sanitize_email_headers(msg)\n\nserialized_msg = msg.as_string()\n\nprint(serialized_msg)\n","payload_needed":true,"payload":"```python\n'Injected-Header: malicious_value\\n'\n```","payload_status":"available","published_fix":[{"repository":"python\/cpython","commit_url":"https:\/\/github.com\/python\/cpython\/commit\/06f28dc236708f72871c64d4bc4b4ea144c50147","commit_subject":"[3.10] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122609)","units":[{"file":"Lib\/email\/generator.py","function":null},{"file":"Lib\/email\/_header_value_parser.py","function":"_refold_parse_tree"}]},{"repository":"python\/cpython","commit_url":"https:\/\/github.com\/python\/cpython\/commit\/4766d1200fdf8b6728137aa2927a297e224d5fa7","commit_subject":"[3.12] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122599)","units":[{"file":"Lib\/email\/errors.py","function":null},{"file":"Lib\/email\/generator.py","function":null},{"file":"Lib\/email\/generator.py","function":"Generator._write_headers"},{"file":"Lib\/email\/_header_value_parser.py","function":null},{"file":"Lib\/email\/_header_value_parser.py","function":"_refold_parse_tree"},{"file":"Lib\/email\/_policybase.py","function":null}]},{"repository":"python\/cpython","commit_url":"https:\/\/github.com\/python\/cpython\/commit\/b158a76ce094897c870fb6b3de62887b7ccc33f1","commit_subject":"[3.8] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122611)","units":[{"file":"Lib\/email\/generator.py","function":"Generator._write_headers"}]},{"repository":"python\/cpython","commit_url":"https:\/\/github.com\/python\/cpython\/commit\/f7c0f09e69e950cf3c5ada9dbde93898eb975533","commit_subject":"[3.11] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122608)","units":[{"file":"Lib\/email\/_header_value_parser.py","function":"_refold_parse_tree"}]}],"references":null}