Semgrep fixes

This commit is contained in:
Ben Meadors
2026-04-17 18:06:36 -05:00
parent 8e635bc2fb
commit 405c8b951b
2 changed files with 19 additions and 1 deletions
+16
View File
@@ -98,8 +98,24 @@ def install() -> None:
return
import importlib
# Whitelist the exact module paths this function is ever allowed to
# import. `module_path` below is iterated from `_TOOL_MAP` — a file-
# local, hardcoded dict literal — but a static whitelist makes the
# "no untrusted input here" invariant legible to reviewers and to
# the Semgrep `non-literal-import` audit rule.
_allowed_modules = frozenset(path for path, _attr in _TOOL_MAP.values())
for tool_name, (module_path, attr) in _TOOL_MAP.items():
# Defense in depth: if someone mutates `_TOOL_MAP` at runtime
# (shouldn't happen; it's module-level) the whitelist catches it.
if module_path not in _allowed_modules:
continue
try:
# nosemgrep: python.lang.security.audit.non-literal-import.non-literal-import
# `module_path` is a key from the hardcoded `_TOOL_MAP` dict
# and is gated above by membership in `_allowed_modules`
# (itself derived from the same literal values). There is no
# path for untrusted input to reach this call.
mod = importlib.import_module(module_path)
except ImportError:
continue