T05 · Unauthorized Access and Privilege Escalation
- Location
preview_3d.py:12- Finding
Path Traversal Through Unvalidated Scene Names
- Content
View full analysis
Vulnerability Details
File Location:
preview_3d.py, lines 12, 17, 27, 49, 52, and 69
Vulnerability Type: Path traversal and unauthorized filesystem access
Risk Level: HighVulnerable Code
python with open(os.path.join(DIR, f"{args.name}.json"), 'w') as f: json.dump(scene, f, ensure_ascii=False, indent=2)python path = os.path.join(DIR, f"{args.scene}.json") if not os.path.exists(path): return with open(path) as f: scene = json.load(f)python output = os.path.join(DIR, f"{args.scene}_preview.html") with open(output, 'w', encoding='utf-8') as f: f.write(html)Technical Analysis
Scene names supplied through
args.nameandargs.sceneare directly interpolated into filesystem paths.os.path.join()does not prevent path traversal and does not verify that the resulting path remains under the intendedscenesdirectory.A value containing parent-directory components, such as
../../target, produces a path equivalent to:text scenes/../../target.jsonThe operating system resolves these components before opening the file. Consequently, the
create_scene,add_object,render_ascii, andexport_threejsoperations can access paths outside the designated scene-storage directory.The
.jsonand_preview.htmlsuffixes constrain the exact filenames that can be targeted, but they do not provide directory containment. Theadd_objectand export operations can also read attacker-selected JSON files when those files exist and contain the expected structure.Attack Path
- The attacker invokes
create_scenewith a traversal-based scene name, for example:text ../../target - The application constructs:
text <project>/scenes/../../target.json - Filesystem path normalization resolves this outside the
scenesdirectory. - The process creates or overwrites
target.json...[truncated 1166 chars]
- The attacker invokes
- Remediation
View remediation
Remediation Suggestions
- Restrict scene identifiers to a conservative allowlist, such as ASCII letters, digits, underscores, and hyphens:
python import re if not re.fullmatch(r"[A-Za-z0-9_-]+", scene_name): raise ValueError("Invalid scene name") - Resolve and validate every path before opening it:
python from pathlib import Path SCENE_DIR = (Path(__file__).resolve().parent / "scenes").resolve() def scene_path(name: str, suffix: str = ".json") -> Path: if not re.fullmatch(r"[A-Za-z0-9_-]+", name): raise ValueError("Invalid scene name") candidate = (SCENE_DIR / f"{name}{suffix}").resolve() if candidate.parent != SCENE_DIR: raise ValueError("Path escapes the scene directory") return candidate - Use the validated helper consistently for creation, loading, modification, rendering, and HTML export.
- Reject absolute paths, path separators, parent-directory components, null bytes, and platform-specific alternate separators.
- Avoid silently overwriting existing files. Use exclusive creation mode where appropriate or require explicit overwrite authorization.
- Run the Skill under a least-privileged account with write access limited to the designated scene directory.
- Add tests covering
../, absolute paths, repeated separators, encoded traversal forms, and Windows-style separators.
- Restrict scene identifiers to a conservative allowlist, such as ASCII letters, digits, underscores, and hyphens:
