T09 · Insecure Skill Coding Practices
- Location
scripts/adversarial_verify.py:71- Finding
Untrusted Target Module Executes During Rule Verification
- Content
View full analysis
Vulnerability Details
File Location:
scripts/adversarial_verify.py, lines 71-79
Vulnerability Type: Unsafe in-process execution of untrusted Python code
Risk Level: HighVulnerable Code
python def _load_rules_from_skill(skill_dir): """Attempt to load RULES from scripts/adv_rules.py in the student skill.""" cand = os.path.join(skill_dir, "scripts", "adv_rules.py") if not os.path.isfile(cand): return None spec = importlib.util.spec_from_file_location("adv_rules", cand) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return getattr(mod, "RULES", None)Technical Analysis
The verifier loads a Python module from a user-supplied skill directory and invokes
exec_module()in the verifier process. Importing a Python module executes all of its top-level statements before theRULESattribute is retrieved.The target skill is precisely the artifact being assessed, so its
scripts/adv_rules.pyfile cannot safely be assumed to be trusted. No validation, sandbox, subprocess boundary, privilege restriction, resource limit, network restriction, or user confirmation is applied before execution.Although the path is constructed with
os.path.join()rather than passed to a shell, this does not prevent code execution because the selected file is deliberately interpreted as Python.Attack Path
- An attacker creates or modifies a student skill directory.
- The attacker places malicious top-level Python statements in
scripts/adv_rules.py. - A user runs the documented verification command against that directory.
_load_rules_from_skill()creates an import specification for the attacker-controlled file.spec.loader.exec_module(mod)executes the malicious statements before validating or retrievingRULES.- The statements run with the same operating-system identity, environment, filesystem access, and network acce ...[truncated 815 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace executable Python rule modules with a declarative, strictly validated format such as JSON containing supported operators, operands, weights, and test cases.
- If callable Python rules are unavoidable, never import them into the verifier process.
- Execute target rules in a disposable sandbox or container using an unprivileged identity.
- Remove secrets from the sandbox environment and mount host data read-only, exposing only the minimum required input files.
- Disable outbound network access and prevent access to sensitive host paths.
- Apply CPU, memory, process-count, file-size, and execution-time limits.
- Use a narrowly defined serialization protocol for inputs and outputs rather than sharing Python objects.
- Validate the returned rule schema, data types, weights, and case limits before processing results.
- Clearly warn users that executable rules are untrusted and require explicit confirmation before evaluation.
- Do not treat AST inspection or import-name filtering as a sufficient sandbox; Python code must be isolated at the process and operating-system level.
