GHSA-m66c-fw79-6359: Medium severity pip/eml_parser vulnerability
Summary
emlparser uses the email.utils.getaddresses() function from the CPython standard library to parse e-mail headers that contain e-mail addresses (such as To, Cc, Bcc, From, Reply-To, Sender, ...). When the input header contains a deeply nested CFWS (comment / folding white space) construct, the recursive descent parser in the standard library exhausts the call stack. The resulting RecursionError is not caught by emlparser, so the exception propagates and aborts parsing of the whole message.
Impact
SOC pipelines use emlparser to process untrusted e-mails. An attacker can easily create an eml file that will trigger the RecursionError during parsing.
The impact is mitigated by the fact that there are various other situations in which emlparser will raise an exception when attempting to parse a malformed or pathological eml file. In particular, very deeply nested multipart e-mails also result in a RecursionError being raised by the library voluntarily. Therefore, systems relying on emlparser already need to detect and handle errors emanating from the library in an appropriate way.
Workarounds
The issue can be avoided by wrapping the call to emlparser.decodeemail or emlparser.decodeemailbytes in a try/except construct.
Patches
Since version 3.0.2, emlparser will catch the error in the standard library parser and fall back to a simpler parser based on a regular expression.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/eml_parserto a version that resolves this vulnerability.Fixed in 3.0.2 - Upgrade
Upgrade
eml_parserto a version that resolves this vulnerability.Fixed in 3.0.2 - Configuration
Wrap calls to eml_parser.decode_email and eml_parser.decode_email_bytes in a try/except construct, because the resulting RecursionError is not caught by eml_parser and otherwise propagates to abort parsing of the whole message.
SOC pipeline using eml_parser Wrap decode calls in try/except = try/except around eml_parser.decode_email and eml_parser.decode_email_bytes
Event History
Frequently Asked Questions
Which deployments are realistically exposed to this issue?
Systems that use eml_parser to process untrusted e-mail messages, such as SOC pipelines, are exposed. A crafted message containing deeply nested comment or folding-whitespace constructs in address-bearing headers can abort parsing.
What does an attacker need to do to trigger the failure?
The attacker needs to supply an EML file with a deeply nested CFWS construct in a header parsed as e-mail addresses, including headers such as To, Cc, Bcc, From, Reply-To, or Sender. No authentication or user interaction is indicated by the supplied severity vector.
What can be done if an update cannot be applied immediately?
Wrap eml_parser calls so that exceptions, including RecursionError, are detected and handled rather than allowed to abort processing. This is also appropriate for other malformed or pathological messages, since deeply nested multipart messages can already cause RecursionError.