T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/search_model.py:16- Finding
Out-of-Scope Model Data Access Due to Incorrect Path Resolution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_model.py, lines 16–36
Vulnerability Type: Improper filesystem scope and path resolution
Risk Level: MediumVulnerable Code
python def get_data_dir(): """获取数据目录路径""" # 如果在 skill 目录中运行,向上找到项目根目录 script_dir = Path(__file__).resolve().parent skill_dir = script_dir.parent project_dir = skill_dir.parent.parent.parent return project_dir / "data" def load_all_models(): """加载所有型号数据""" data_dir = get_data_dir() models_dir = data_dir / "models" all_models = [] if models_dir.exists(): for json_file in models_dir.glob("*.json"): try: with open(json_file, 'r', encoding='utf-8') as f: data = json.load(f) if 'models' in data: all_models.extend(data['models'])Technical Analysis
The script intends to locate the bearing database relative to the Skill directory. However, it traverses three parent directories above
skill_dir:python project_dir = skill_dir.parent.parent.parentIn the audited deployment layout, the script is stored at:
text /tmp/.../artifact/scripts/search_model.pyTherefore,
skill_dirresolves to/tmp/.../artifact, while traversing three additional parents resolvesproject_dirto the filesystem root,/. The resulting data directory is consequently:text /data/modelsThis contradicts the Skill documentation, which describes a Skill-local
data/models/directory. The script then enumerates and opens every*.jsonfile in the external/data/modelsdirectory using the privileges of the running agent process.No path-containment check verifies that the resolved database remains inside the Skill package. No schema or type validation is applied before external model fields are consumed and displayed. As a result, model se ...[truncated 1602 chars]
- Remediation
View remediation
Remediation Suggestions
Resolve the database directly beneath the Skill root rather than traversing above it:
python def get_data_dir(): skill_dir = Path(__file__).resolve().parent.parent data_dir = (skill_dir / "data").resolve() if not data_dir.is_relative_to(skill_dir): raise RuntimeError("Data directory is outside the Skill root") return data_dirAdditional hardening measures should include:
- Package the documented
data/models/directory with the Skill. - Resolve and validate every model file before opening it, ensuring it remains beneath the expected models directory.
- Reject symlinked model files if symlinks are not explicitly required.
- Validate each JSON document against a strict schema, including required keys and expected value types.
- Place limits on file size, record count, string length, and nesting depth to reduce resource-exhaustion risk.
- Sanitize or escape non-printable terminal control characters before displaying external string values.
- Fail closed with an explicit configuration error when the packaged database directory is missing rather than silently consulting an unintended external location.
- Package the documented
