betterwithage commited on
Commit
aa870fc
·
verified ·
1 Parent(s): 39d0750

harden(a11oy): mirror killinchu #150 bandit HIGH fix (MD5 usedforsecurity, XML-RPC defusedxml) — byte-identical shared modules

Browse files

HARDEN-DEEP reconcile mirror of killinchu PR #150 into the a11oy HF Space.
szl_unay.py / szl_waqay.py: MD5 feature-hash usedforsecurity=False (B324).
szl_connectors/erp/odoo.py: XML-RPC hardened via defusedxml.xmlrpc.monkey_patch() (B411).
Byte-identical to killinchu post-#150 and to GitHub a11oy canonical bytes.
Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>

Files changed (3) hide show
  1. szl_connectors/erp/odoo.py +14 -2
  2. szl_unay.py +1 -1
  3. szl_waqay.py +1 -1
szl_connectors/erp/odoo.py CHANGED
@@ -29,8 +29,20 @@ _UA = "SZL-Connectors/1.0 (odoo xml-rpc)"
29
 
30
 
31
  def _xmlrpc(url: str, method: str, params: list) -> Any:
32
- """Minimal XML-RPC client (stdlib only). Returns parsed result or raises."""
33
- import xmlrpc.client as xc
 
 
 
 
 
 
 
 
 
 
 
 
34
  transport = xc.SafeTransport() if url.startswith("https") else xc.Transport()
35
  proxy = xc.ServerProxy(url, transport=transport, allow_none=True)
36
  fn = getattr(proxy, method)
 
29
 
30
 
31
  def _xmlrpc(url: str, method: str, params: list) -> Any:
32
+ """Minimal XML-RPC client. Returns parsed result or raises.
33
+
34
+ Hardened against XML-decompression / entity-expansion attacks on the Odoo
35
+ response (B411): if defusedxml is present we monkey-patch the stdlib xmlrpc
36
+ parser before use. defusedxml is pinned in the Docker image; if it is absent
37
+ in a bare runtime we degrade to the stdlib parser rather than crash — the
38
+ connector only ever parses responses from an operator-configured Odoo host.
39
+ """
40
+ try:
41
+ import defusedxml.xmlrpc as _dx
42
+ _dx.monkey_patch()
43
+ except Exception:
44
+ pass
45
+ import xmlrpc.client as xc # nosec B411 - parser hardened above via defusedxml.xmlrpc.monkey_patch()
46
  transport = xc.SafeTransport() if url.startswith("https") else xc.Transport()
47
  proxy = xc.ServerProxy(url, transport=transport, allow_none=True)
48
  fn = getattr(proxy, method)
szl_unay.py CHANGED
@@ -88,7 +88,7 @@ def embed(text: str, dim: int = EMBED_DIM) -> List[float]:
88
  for i in range(len(s) - 2):
89
  grams.append(s[i : i + 3])
90
  for g in grams:
91
- h = int(hashlib.md5(g.encode("utf-8")).hexdigest(), 16)
92
  idx = h % dim
93
  sign = 1.0 if (h >> 8) & 1 else -1.0
94
  vec[idx] += sign
 
88
  for i in range(len(s) - 2):
89
  grams.append(s[i : i + 3])
90
  for g in grams:
91
+ h = int(hashlib.md5(g.encode("utf-8"), usedforsecurity=False).hexdigest(), 16)
92
  idx = h % dim
93
  sign = 1.0 if (h >> 8) & 1 else -1.0
94
  vec[idx] += sign
szl_waqay.py CHANGED
@@ -742,7 +742,7 @@ def _hash_embed(text: str, dim: int = 128) -> List[float]:
742
  Pure-Python (returns a plain list) — no numpy needed."""
743
  vec = [0.0] * dim
744
  for tok in (text.lower().split()):
745
- h = int(hashlib.md5(tok.encode("utf-8")).hexdigest(), 16)
746
  vec[h % dim] += 1.0 if (h >> 8) & 1 else -1.0
747
  nrm = math.sqrt(sum(x * x for x in vec))
748
  return [x / nrm for x in vec] if nrm > 1e-9 else vec
 
742
  Pure-Python (returns a plain list) — no numpy needed."""
743
  vec = [0.0] * dim
744
  for tok in (text.lower().split()):
745
+ h = int(hashlib.md5(tok.encode("utf-8"), usedforsecurity=False).hexdigest(), 16)
746
  vec[h % dim] += 1.0 if (h >> 8) & 1 else -1.0
747
  nrm = math.sqrt(sum(x * x for x in vec))
748
  return [x / nrm for x in vec] if nrm > 1e-9 else vec