T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/search_model.py:20- Finding
Out-of-Scope JSON File Access Caused by Incorrect Data-Directory Resolution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_model.py, lines 20–33
Vulnerability Type: Out-of-scope filesystem access
Risk Level: MediumVulnerable Code
python 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:Technical Analysis
The script intends to locate a data directory associated with the Skill, but it traverses three parent directories above the Skill root. Given the audited deployment path,
script_dirresolves to theartifact/scriptsdirectory andskill_dirresolves toartifact. Consequently,skill_dir.parent.parent.parentresolves to the filesystem root, causing the effective data path to become/data.The script therefore reads every matching
/data/models/*.jsonfile instead of files under the Skill's own data directory. This violates the least-privilege boundary and conflicts with the data layout documented inSKILL.md.Files are opened using the permissions of the process running the Skill. The code does not itself elevate operating-system privileges, but it can access unrelated files that the invoking process is already authorized to read. Parsed records are trusted without schema validation and are subsequently used as model data.
Attack Path
- An attacker or another application creates or modifies a JSON file under
/data/models. - The attacker supplies a document containing a
modelscollection with crafted, misleading, or malformed model records. - A user or Agent invokes
scripts/search_model.pyfor a bearing model. - `get_data_di ...[truncated 1283 chars]
- An attacker or another application creates or modifies a JSON file under
- Remediation
View remediation
Remediation Suggestions
Resolve the data directory directly relative to the Skill root:
python def get_data_dir(): skill_dir = Path(__file__).resolve().parent.parent return skill_dir / "data"Apply the following additional hardening measures:
- Resolve both the trusted data root and each candidate file with
Path.resolve(). - Verify that every resolved candidate remains beneath the trusted Skill data directory before opening it.
- Reject symbolic links if model data may be stored in a directory writable by untrusted users.
- Validate JSON documents against a strict schema before using model records.
- Replace direct required-field access such as
model['model']with validated access after confirming field types and presence. - Package the documented
data/modelsdirectory with the Skill or fail explicitly when it is absent. - Add automated tests asserting that
get_data_dir()resolves to the Skill-localdatadirectory and never to/dataor another ancestor directory.
- Resolve both the trusted data root and each candidate file with
