code-injection: src/supervisor/tools.py:26
evaluated
medium
scan
supervisor
2026-03-31 17:21
Next step: Review the evaluation below, then approve or reject.
Location
src/supervisor/tools.py:26
python
Pattern: compile() may execute dynamic code
Code Context
21
22logger = logging.getLogger(__name__)
23
24# ── Validation helpers ────────────────────────────────────────────
25
26_SAFE_SERVICE_NAME = re.compile(r"^[a-zA-Z0-9._-]+$")
27_SAFE_PATH = re.compile(r"^/[a-zA-Z0-9_./ -]+$")
28
29# Commands allowed via run_diagnostic (read-only system inspection)
30_DIAGNOSTIC_ALLOWLIST = {
31 "docker ps",
Evaluation
●
Agent analyzing code...
Verdict: false_positive
Reasoning: This is a static regex pattern compilation, not dynamic code execution. The flagged line 26 is `re.compile(r"^[a-zA-Z0-9._-]+$")` which compiles a hardcoded, constant regex pattern at module load time. The pattern string is a literal in the source code, not derived from user input. The confusion likely stems from a SAST tool flagging any use of `compile()` without distinguishing between `re.compile()` (safe pattern compilation) and `compile()` (Python code compilation). User input only flows through the `.match()` method at tools.py:131 and tools.py:417 within `_validate_service_name()`, which is used as an input sanitizer in `_tool_check_service_status()` (line 383-391) and `_tool_check_logs()` (line 414-423). The regex is explicitly designed to *prevent* code injection by restricting service names to alphanumeric characters, dots, hyphens, and underscores only, blocking shell metacharacters. This is confirmed by comprehensive injection tests in tests/test_tools.py:21-69 that verify it blocks `;`, `|`, backticks, `&&`, and `$()`.
Effort: trivial
Actions
Job History (1)
| Type | Status | Started | Duration | Error | |
|---|---|---|---|---|---|
| evaluate | completed | 2026-04-01 12:48 | 23s | - |