T09 · Insecure Skill Coding Practices
- Location
tests/test_core.py:20- Finding
Test Suite Executes Untrusted Code Outside the Project Boundary
- Content
View full analysis
Vulnerability Details
File Location:
tests/test_core.py:20-21,tests/test_core.py:52-64,tests/test_core.py:81-94, andtests/test_core.py:105-116
Vulnerability Type: Execution and import of ambient code outside the audited project
Risk Level: HighVulnerable Code
python self.workspace_root = Path(__file__).parent.parent.parent self.memory_dir = self.workspace_root / 'memory'python self.workspace_root = Path(__file__).parent.parent.parent self.script_path = self.workspace_root / 'scripts' / 'pilot_check_stage3.py' import subprocess result = subprocess.run( ['python3', str(self.script_path), '测试任务'], capture_output=True, text=True, timeout=10 )python self.workspace_root = Path(__file__).parent.parent.parent self.script_path = self.workspace_root / 'scripts' / 'daily_memory_check.py' import subprocess result = subprocess.run( ['python3', str(self.script_path)], capture_output=True, text=True, timeout=30 )python self.workspace_root = Path(__file__).parent.parent.parent self.design_path = self.workspace_root / 'scripts' / 'smart_adaptive_mem0_design.py' sys.path.insert(0, str(self.workspace_root / 'scripts')) from smart_adaptive_mem0_design import SmartRouterTechnical Analysis
The test suite treats the parent of the project directory as its workspace. From
artifact/tests/test_core.py, evaluatingPath(__file__).parent.parent.parentresolves above theartifactproject root. The tests subsequently execute Python files from that external location throughsubprocess.runand import another external module after placing the external directory at the beginning ofsys.path.Neither operation verifies that the resolved scripts are part of the audited package, checks file ownership or permissions, validates a cryptographic digest, or constrains the imported code. Python module imports ex ...[truncated 1992 chars]
- Remediation
View remediation
Remediation Suggestions
-
Derive the project root without escaping the repository:
python project_root = Path(__file__).resolve().parents[1] scripts_dir = project_root / "tests" / "fixtures" / "scripts" -
Keep every executable test fixture inside the repository so it is included in review and version control.
-
Do not prepend an ambient parent directory to
sys.path. Import project modules through the package's normal import path. -
Replace execution of real workspace scripts with temporary fixtures created under a test-controlled temporary directory.
-
Mock
subprocess.runwhen the test only needs to verify invocation behavior. -
Before executing any fixture, resolve its path and enforce containment:
python candidate = (scripts_dir / script_name).resolve() candidate.relative_to(project_root) -
Run tests in an isolated environment with minimal filesystem access, no unnecessary secrets, restricted network access, and a non-privileged account.
-
Add a regression test confirming that all subprocess targets and dynamically imported modules resolve beneath the project root.
-
