T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/main.py:18- Finding
Recursive Source Scan Escapes the Intended Project Boundary
- Content
View full analysis
list: """搜索与关键词相关的代码""" results = [] py_files = list(project_root.glob("**/*.py")) py_files = [f for f in py_files if ".opencode" not in str(f) and "skill" not in f.name.lower()] priority_score = { "def ": 3, "class ": 3, "async def ": 3, "import ": 1, "from ": 1, } for py_file in py_files: try: content = py_file.read_text(encoding="utf-8") ``` ```python results = search_code(keywords, PROJECT_ROOT) ``` ### Technical Analysis `main.py` is located under `artifact/scripts/`. Evaluating `Path(__file__).parent.parent.parent` therefore selects the directory containing `artifact`, rather than the Skill directory or a project directory explicitly authorized by the user. The program then recursively enumerates every Python file beneath that broader directory and reads each matching file. The only exclusions are paths containing `.opencode` and filenames containing `skill`; these filters do not establish a security boundary and do not prevent access to sibling projects. Search results include matching source lines and may select the highest-priority match as the test target. Consequently, source code outside the intended project can be read, displayed, and incorporated into generated test artifacts. ### Attack Path 1. Place or identify a sibling project under the parent directory selected by `PROJECT_ROOT`. 2. Invoke the Skill with a requirement or keyword matching a function, class, import, or source line in that sibling project. 3. `glob("**/*.py")` recursively discovers the sibling file. 4. `read_text()` re ...[truncated 836 chars]- Remediation
View remediation
bool: try: path.resolve().relative_to(project_root) return True except ValueError: return False py_files = [ path for path in project_root.rglob("*.py") if is_within_project(path) ] ``` ]]>
