fix(security): harden connector ingress parser paths

This commit is contained in:
rookiestar28
2026-04-08 02:18:00 +08:00
parent 28975b1f22
commit 92ebb2b113
4 changed files with 16 additions and 14 deletions
+3 -4
View File
@@ -123,10 +123,9 @@ def _make_json_response(web_mod, data: Dict[str, Any], *, status: int = 200):
)
def _safe_external_error_code(default: str, exc: Exception) -> str:
raw = str(exc or "").strip()
if raw and len(raw) <= 64 and raw.replace("_", "").replace("-", "").isalnum():
return raw
def _safe_external_error_code(default: str, _exc: Exception) -> str:
# IMPORTANT: keep Feishu external failures constant. Returning exception-
# derived codes/text here reopens the residual CodeQL stack-trace finding.
return default
+3 -4
View File
@@ -97,10 +97,9 @@ def _make_redirect_response(web_mod, url: str):
return _CompatResponse(status=302, text=url)
def _safe_external_error_text(default: str, exc: Exception) -> str:
raw = str(exc or "").strip()
if raw and len(raw) <= 64 and raw.replace("_", "").replace("-", "").isalnum():
return raw
def _safe_external_error_text(default: str, _exc: Exception) -> str:
# IMPORTANT: keep Slack external failures constant. Even "short safe-looking"
# exception text remains scanner-tainted and can re-expose internal detail.
return default
+7 -4
View File
@@ -32,6 +32,9 @@ import time
from typing import Optional
from xml.etree import ElementTree as ET
from defusedxml import ElementTree as DefusedET
from defusedxml.common import DefusedXmlException
from ..config import ConnectorConfig
from ..contract import CommandRequest, CommandResponse
from ..router import CommandRouter
@@ -272,10 +275,10 @@ def parse_wechat_xml(raw: bytes) -> dict:
raise XMLBudgetExceeded("DTD/entity declarations are not allowed")
try:
parser = ET.XMLParser()
parser.feed(raw.decode("utf-8"))
root = parser.close()
except (ET.ParseError, UnicodeDecodeError) as e:
# IMPORTANT: keep defusedxml here. Reverting to the stdlib parser path
# reopens the residual CodeQL xml-bomb finding on this ingress seam.
root = DefusedET.fromstring(raw.decode("utf-8"))
except (ET.ParseError, DefusedXmlException, UnicodeDecodeError) as e:
raise XMLBudgetExceeded(f"XML parse error: {e}") from e
# Depth check — WeChat envelopes are <xml><Tag>val</Tag></xml>, depth=2
+3 -2
View File
@@ -6,8 +6,9 @@ license = {text = "MIT"}
readme = "README.md"
requires-python = ">=3.10"
# S57: cryptography is required for Fernet AEAD secrets-at-rest encryption
dependencies = ["cryptography>=41.0"]
# S57: cryptography is required for Fernet AEAD secrets-at-rest encryption.
# S85: defusedxml is required for scanner-recognized fail-closed WeChat XML parsing.
dependencies = ["cryptography>=41.0", "defusedxml>=0.7.1"]
[project.optional-dependencies]
# WeChat AES encrypted ingress mode (R82) — lazy-imported, only needed when encrypt_type=aes