Skip to content

Commit c06375b

Browse files
author
Oracles Technologies LLC
committed
security: replace diskcache with cachetools to remediate CVE-2025-69872
diskcache 5.6.3 has an unpatched vulnerability with no fix available. Replace with cachetools.TTLCache (in-memory, thread-safe via Lock) to eliminate the attack surface entirely. Also migrate scripts from --license-key/ETHICORE_LICENSE_KEY to --api-key/ETHICORE_API_KEY and fix ONNX opset detection in retrain_guardian_model.py.
1 parent e50d917 commit c06375b

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

requirements.lock

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# requirements.lock — hash-pinned dependency lockfile for ethicore-engine-guardian
2-
#
3-
# Every package (direct and transitive) is pinned to an exact version and
4-
# verified by SHA-256 hash on install. This prevents a silently-compromised
5-
# upstream release from being pulled in automatically.
6-
#
7-
# Usage:
8-
# pip install --require-hashes -r requirements.lock # reproducible install
9-
#
10-
# To regenerate after updating requirements.txt:
11-
# pip install pip-tools
12-
# pip-compile --generate-hashes --output-file=requirements.lock requirements.txt
131
#
142
# This file is autogenerated by pip-compile with Python 3.11
153
# by the following command:
@@ -24,14 +12,14 @@ asyncio-throttle==1.0.2 \
2412
--hash=sha256:2675282e99d9129ecc446f917e174bc205c65e36c602aa18603b4948567fcbd4 \
2513
--hash=sha256:4d4c1eb3250f735f59ce842d8d92cd2927c008bd52008797ba030b5787c41f3b
2614
# via -r requirements.txt
15+
cachetools==7.0.6 \
16+
--hash=sha256:4e94956cfdd3086f12042cdd29318f5ced3893014f7d0d059bf3ead3f85b7f8b \
17+
--hash=sha256:e5d524d36d65703a87243a26ff08ad84f73352adbeafb1cde81e207b456aaf24
18+
# via -r requirements.txt
2719
colorama==0.4.6 \
2820
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
2921
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
3022
# via loguru
31-
diskcache==5.6.3 \
32-
--hash=sha256:2c3a3fa2743d8535d832ec61c2054a1641f41775aa7c556758a109941e33e4fc \
33-
--hash=sha256:5e31b2d5fbad117cc363ebaf6b689474db18a1f6438bc82358b024abd4c2ca19
34-
# via -r requirements.txt
3523
flatbuffers==25.12.19 \
3624
--hash=sha256:7634f50c427838bb021c2d66a3d1168e9d199b0607e6329399f04846d42e20b4
3725
# via onnxruntime

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tenacity>=8.2.0
1515
# google-generativeai>=0.3.0
1616

1717
# Performance and caching
18-
diskcache>=5.6.0
18+
cachetools>=5.3.0
1919
asyncio-throttle>=1.0.2
2020

2121
# Development dependencies (install with pip install -e ".[dev]")

scripts/regenerate_embeddings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ def main(argv: list[str] | None = None) -> int:
264264
help="Explicit output path for threat_embeddings.json (overrides auto-resolve).",
265265
)
266266
parser.add_argument(
267-
"--license-key",
267+
"--api-key",
268268
metavar="KEY",
269269
default=None,
270270
help=(
271-
"License key (overrides $ETHICORE_LICENSE_KEY env var). "
272-
"Enables licensed 51-category fingerprint set."
271+
"API key (overrides $ETHICORE_API_KEY env var). "
272+
"Enables licensed 68-category fingerprint set."
273273
),
274274
)
275275
parser.add_argument(
@@ -284,7 +284,7 @@ def main(argv: list[str] | None = None) -> int:
284284
args = parser.parse_args(argv)
285285

286286
# Resolve credentials: CLI arg > env var
287-
license_key = args.license_key or os.environ.get("ETHICORE_LICENSE_KEY") or None
287+
license_key = args.api_key or os.environ.get("ETHICORE_API_KEY") or None
288288
assets_dir = args.assets_dir or os.environ.get("ETHICORE_ASSETS_DIR") or None
289289

290290
# Trim whitespace so copy-paste from shell doesn't silently break validation

scripts/retrain_guardian_model.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
pip install scikit-learn skl2onnx onnxruntime onnx numpy
2828
2929
Usage:
30-
# Licensed (51 categories, 444 fingerprints) — recommended:
31-
ETHICORE_LICENSE_KEY="EG-PRO-..." python scripts/retrain_guardian_model.py
30+
# Licensed (68 categories, 624 fingerprints) — recommended:
31+
ETHICORE_API_KEY="eg-sk-..." python scripts/retrain_guardian_model.py
3232
3333
# Community (5 categories):
3434
python scripts/retrain_guardian_model.py
@@ -832,7 +832,7 @@ async def _compute_semantic_embeddings(
832832
"""
833833
from ethicore_guardian.analyzers.semantic_analyzer import SemanticAnalyzer
834834

835-
analyzer = SemanticAnalyzer(license_key=license_key, assets_dir=assets_dir)
835+
analyzer = SemanticAnalyzer(api_key=license_key, assets_dir=assets_dir)
836836
ok = await analyzer.initialize()
837837
model_label = "ONNX MiniLM" if (ok and analyzer.session) else "hash-based fallback"
838838
print(f" Semantic model: {model_label}")
@@ -1094,7 +1094,13 @@ def _train_and_export(
10941094
)
10951095

10961096
# Unsqueeze axes
1097-
opset_version = onnx_model.opset_import[0].version if onnx_model.opset_import else 11
1097+
# skl2onnx may place ai.onnx.ml domain at index 0 (version ~3), which would
1098+
# incorrectly trigger the opset-11 path. Scan all imports for the main domain.
1099+
opset_version = 11 # conservative default
1100+
for _opset in onnx_model.opset_import:
1101+
if _opset.domain in ("", "ai.onnx"):
1102+
opset_version = _opset.version
1103+
break
10981104
if opset_version >= 13:
10991105
axes_name = "_unsqueeze_axes"
11001106
axes_init = numpy_helper.from_array(np.array([1], dtype=np.int64), name=axes_name)
@@ -1239,8 +1245,8 @@ def main(argv=None) -> int:
12391245
help="Overwrite existing model without prompting.")
12401246
parser.add_argument("--out", metavar="PATH", default=None,
12411247
help="Output path for guardian-model.onnx.")
1242-
parser.add_argument("--license-key", metavar="KEY", default=None,
1243-
help="License key (overrides $ETHICORE_LICENSE_KEY).")
1248+
parser.add_argument("--api-key", metavar="KEY", default=None,
1249+
help="API key (overrides $ETHICORE_API_KEY).")
12441250
parser.add_argument("--assets-dir", metavar="DIR", default=None,
12451251
help="Asset bundle path (overrides $ETHICORE_ASSETS_DIR).")
12461252
parser.add_argument("--samples", type=int, default=30000,
@@ -1251,7 +1257,7 @@ def main(argv=None) -> int:
12511257
help="Random seed (default: 42).")
12521258
args = parser.parse_args(argv)
12531259

1254-
license_key = (args.license_key or os.environ.get("ETHICORE_LICENSE_KEY") or "").strip() or None
1260+
license_key = (args.api_key or os.environ.get("ETHICORE_API_KEY") or "").strip() or None
12551261
assets_dir = (args.assets_dir or os.environ.get("ETHICORE_ASSETS_DIR") or "").strip() or None
12561262

12571263
try:

0 commit comments

Comments
 (0)