Skip to content

Commit b5b8cd8

Browse files
authored
Merge pull request PowerGridModel#387 from PowerGridModel/fix-defusedxml-deps
Revert to default XML parser
2 parents 608e961 + 7aab359 commit b5b8cd8

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

docs/converters/tabular_converter.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,12 @@ Mapping files enable the specification of custom mappings or filter functions.
381381
These functions can come from the `power-grid-model-io` library, be user-provided, or even supplied by third parties.
382382
To ensure security, we have implemented several measures.
383383
Best practices are recommended to prevent malicious code execution.
384-
XML parsing is performed using the defusedxml library instead of the standard library xml module.
385-
This ensures that unsafe XML features are disabled by default when processing mapping files or related inputs.
386-
[Python XML security](https://docs.python.org/3/library/xml.html#xml-security)
384+
XML parsing is performed using the standard library's `xml` module. For `python < 3.11`, `xml` was built
385+
with `expat = 2.6.0` which was vulnerable; however, `python >= 3.11` includes `expat = 2.7.1` which no
386+
longer is.
387+
This ensures that unsafe XML features are disabled by default when processing mapping files or related
388+
inputs. See the this [issue](https://github.com/python/cpython/issues/127502) and the
389+
[Python XML security](https://docs.python.org/3/library/xml.html#xml-security) documentation.
387390

388391
### Safe Loading of Configuration Files
389392

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ select = [
167167
# pytest-style
168168
"PT",
169169
]
170-
ignore = []
170+
ignore = ["S314"] # S314: xml parsing is no longer considered unsafe python >= 3.11 (https://github.com/python/cpython/pull/135294)
171171

172172
[tool.ruff.lint.isort]
173173
# Imports that are imported using keyword "as" and are from the same source - are combined.

src/power_grid_model_io/utils/excel_ambiguity_checker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
- zipfile to handle the Excel file as a ZIP archive for parsing.
2121
"""
2222

23+
import xml.etree.ElementTree as ET
2324
import zipfile
2425
from collections import Counter
2526
from pathlib import Path
2627

27-
from defusedxml import ElementTree as ET
28-
2928
XML_NAME_SPACE = {"": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"} # NOSONAR
3029
WORK_BOOK = "xl/workbook.xml"
3130
SHARED_STR_PATH = "xl/sharedStrings.xml"

0 commit comments

Comments
 (0)