Skip to content

Commit 517fe0e

Browse files
committed
build: Harden XML parser in extract_get.py
build: Emable XML DTD filtering in extract_get.py Gramar validation will prevent noise injection build: Replace the xml parser used in extract_get.py The prevents known attack, Also note that defusedxml (0.7.1) by default (forbid_entities=True, forbid_external=True, see minidom.py reference) - forbid_entities: disallow XML with <!ENTITY> - forbid_dtd: disallow XML with a <!DOCTYPE> - forbid_external: disallow any access to remote or local resources in external entities or DTD Minor py3 cleanup added. Origin: #101 Bug-SiliconLabs: UIC-3662 Relate-to: https://en.wikipedia.org/wiki/Billion_laughs_attack Relate-to: https://docs.python.org/3/library/xml.html#xml-vulnerabilities Relate-to: SLVDBBP-3112666 Relate-to: https://pypi.org/project/defusedxml/#billion-laughs-exponential-entity-expansion Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#42 Relate-to: https://github.com/tiran/defusedxml/blob/v0.7.1/defusedxml/minidom.py#L18 Signed-off-by: Philippe Coval <[email protected]>
1 parent 09ebaa7 commit 517fe0e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

applications/zpc/components/zwave_command_handler/scripts/extract_get.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
# Copyright (c) 2014 Silicon Laboratories Inc.
44

5-
from __future__ import print_function
6-
import xml.dom.minidom
75
import sys
8-
import os.path
6+
7+
from defusedxml import minidom
98

109
gets = []
1110
sets = []
@@ -14,10 +13,8 @@
1413

1514

1615
if __name__ == '__main__':
17-
if(sys.argv[1] == '-'):
18-
x = xml.dom.minidom.parse(sys.stdin)
19-
else:
20-
x = xml.dom.minidom.parse(sys.argv[1])
16+
file = sys.stdin if sys.argv[1] == '-' else sys.argv[1]
17+
x = minidom.parse(file, forbid_dtd=True)
2118

2219
classes = dict()
2320

helper.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ debian_codename?=bookworm
3636
packages?=cmake ninja-build build-essential python3-full ruby clang
3737
packages+=git-lfs unp time file usbutils bsdutils
3838
packages+=nlohmann-json3-dev
39+
packages+=python3-defusedxml # For extract_get.py
3940
# TODO: remove for offline build
4041
packages+=curl wget python3-pip
4142
packages+=expect

0 commit comments

Comments
 (0)