fix(security): defusedxml для парса user-XML (пентест XXE-DOS-01)
Половина XML-парсеров была на defusedxml, половина на сыром xml.etree (тот же паттерн «guard точечно»). Хост-side парсеры (_preprocess_xlsx, xlsx_utils) крутятся без mem-капа → billion-laughs = память-DoS всего сервера. Все parse/fromstring user-XML (.gge/.xlsx) переведены на defusedxml (forbid_dtd). Создание XML (ET.Element в gge_deep) осталось на stdlib. Хирургически — заменены только вызовы, не модуль. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+4
-3
@@ -13,6 +13,7 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from defusedxml.ElementTree import parse as _safe_parse, fromstring as _safe_fromstring # XXE/billion-laughs-safe (пентест XXE-DOS-01)
|
||||
from pathlib import Path
|
||||
|
||||
# Проект-специфичные идентификаторы для обезличивания (scrub в индексаторах).
|
||||
@@ -154,7 +155,7 @@ def parse_estimate_full(path: Path) -> dict:
|
||||
"""Полный разбор ЛСР/ОСР. Возвращает estimate-метаданные + позиции с
|
||||
ресурсным составом, ценами база/текущие, накладными/прибылью, коэффициентами."""
|
||||
try:
|
||||
root = ET.parse(str(path)).getroot()
|
||||
root = _safe_parse(str(path)).getroot()
|
||||
except (ET.ParseError, OSError) as e:
|
||||
return {"error": f"{type(e).__name__}: {e}", "path": str(path)}
|
||||
|
||||
@@ -256,7 +257,7 @@ def parse_estimate_full(path: Path) -> dict:
|
||||
def parse_vor(path: Path) -> dict:
|
||||
"""Разбор ВОР (QuantityTakeoff): секции → работы (объём, формула, ссылка)."""
|
||||
try:
|
||||
root = ET.parse(str(path)).getroot()
|
||||
root = _safe_parse(str(path)).getroot()
|
||||
except (ET.ParseError, OSError) as e:
|
||||
return {"error": f"{type(e).__name__}: {e}", "path": str(path)}
|
||||
|
||||
@@ -296,7 +297,7 @@ def parse_ka(data: bytes) -> list[dict]:
|
||||
обезличивания индексатором).
|
||||
"""
|
||||
try:
|
||||
root = ET.fromstring(data)
|
||||
root = _safe_fromstring(data)
|
||||
except ET.ParseError:
|
||||
return []
|
||||
items = []
|
||||
|
||||
Reference in New Issue
Block a user