Am I affected?
Description
Improper Restriction of XML External Entity Reference vulnerability in xmerl_scan in Erlang OTP xmerl allows an attacker to exhaust the memory of the Erlang VM via an XML document that names an external DTD.
With default options, xmerl_scan:string/1,2 and xmerl_scan:file/1,2 fetch and parse the external DTD named in a <!DOCTYPE root SYSTEM "..."> declaration. fetch_DTD/2 in lib/xmerl/src/xmerl_scan.erl passes every system identifier to the default fetch function, which maps file: and absolute URIs to local paths, and int_file_decl/3 then reads the whole file with file:read_file/1. This happens whether or not validation is enabled, and the allow_entities option, which is false by default since OTP 27, only governs <!ENTITY> declarations and does not stop the fetch. A document naming file:///dev/zero makes the node read without bound until the operating system kills it for lack of memory, and the parse never returns.
This issue affects OTP from OTP 17.0 before OTP 27.3.4.20, OTP 28.5.0.9, and OTP 29.1.3, corresponding to xmerl from 1.3.7 before 2.1.3.4, 2.1.9.1, and 2.2.1. Whether OTP before OTP 17.0, corresponding to xmerl before 1.3.7, is affected is unknown.
Technical analysis
1. DOCTYPE handling. scan_doctype2/3 and scan_doctype3/3 in lib/xmerl/src/xmerl_scan.erl call fetch_DTD/2 once the <!DOCTYPE> declaration ends. fetch_DTD/2 has no clause that skips the fetch when validation is off (that clause is commented out), so every system identifier reaches fetch_and_parse/3.
2. Default fetch. fetch_and_parse/3 calls the scanner's fetch_fun, which defaults to fetch/2. Its helper fetch_URI/2 treats the identifier as a filename: a file: URI or an absolute path resolves to that local path, and a relative name resolves against xmlbase. Only http: identifiers are left unread.
3. Unbounded read. The returned {file, Path} goes to int_file_decl/3, which calls file:read_file/1 on the path and converts the result to a list. file:read_file/1 reads until end of file, so a device such as /dev/zero never returns and the binary heap grows until the operating system kills the VM. The allow_entities default of false does not help: it only rejects <!ENTITY> declarations in scan_markup_decl/2, which runs after the file has been read.
Proof of concept
- Build an XML document whose DOCTYPE names an unbounded local resource, for example
<?xml version="1.0"?><!DOCTYPE root SYSTEM "file:///dev/zero"><root/>. - Parse it with
xmerl_scan:string/1with default options on a Unix host. - The call never returns. The reporter observed binary memory reaching 8, 16, 32 and 64 GB within five seconds on OTP 29.1.2, after which the node was killed for lack of memory.
Weaknesses & attack patterns
Weakness
CWE-611
·
Improper Restriction of XML External Entity Reference
in catalog →
MITRE ↗
Attack patterns
CAPEC-201
·
Serialized Data External Linking
MITRE ↗
An attacker who can supply an XML document to an application that parses it with xmerl_scan using default options makes the node read an unbounded local resource such as /dev/zero. The read exhausts memory and takes the node down for every user of the application.
Affected — Erlang / xmerl Repository ↗
modules · source files · routines
Affected — Erlang
modules · source files · routines
Affected — GitHub / erlang/otp Repository ↗
modules · source files · routines
Workarounds
Pass a fetch_fun that refuses external resources in the option list of xmerl_scan:string/2 or xmerl_scan:file/2, for example {fetch_fun, fun(_ExtSpec, State) -> {ok, not_fetched, State} end}. The scanner then continues without reading or parsing the external DTD.
References
Credits
CVSS breakdown
CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
Exploitability
- Attack Vector
- Local
- Attack Complexity
- Low
- Attack Requirements
- None
- Privileges Required
- None
- User Interaction
- None
Vulnerable System
- Confidentiality
- None
- Integrity
- None
- Availability
- High
Subsequent Systems
- Confidentiality
- None
- Integrity
- None
- Availability
- None