T09 · Insecure Skill Coding Practices
- Location
scripts/review_skill.py:415- Finding
Untrusted symbolic links allow filesystem access outside the reviewed Skill directory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/review_skill.py:415-422andscripts/review_skill.py:556-559
Vulnerability Type: Unrestricted symbolic-link traversal
Risk Level: MediumVulnerable Code
python script_files = list(scripts_dir.glob("*")) if not script_files: return CategoryResult("脚本代码", max_score, max_score, issues) for script_file in script_files: if script_file.is_dir(): continue content = script_file.read_text(encoding="utf-8", errors="ignore")The recursive file-size inspection is also performed without rejecting symbolic links or validating resolved paths:
python large_files = [] for file_path in self.skill_path.rglob("*"): if file_path.is_file(): size = file_path.stat().st_size if size > 1024 * 1024: # Greater than 1 MB large_files.append((file_path.relative_to(self.skill_path), size))Technical Analysis
The reviewed Skill directory must be treated as attacker-controlled input. The implementation enumerates directory entries and then calls
read_text(),is_file(), andstat()without checking whether an entry is a symbolic link. These operations follow symbolic links.Consequently, a file under
scripts/can resolve to a file outside the supplied Skill directory. The reviewer does not compare the resolved file path against the resolved review root before opening it. This violates the expected directory boundary of a read-only package reviewer.The same issue affects recursive file-size inspection. Although
Path.rglob()does not normally recurse through a symbolic link to a directory, symbolic links to files can still be followed byis_file()andstat().Attack Path
- An attacker creates a Skill package containing a symbolic link such as
scripts/check.pypointing to a local file outside the package. - The victim extracts or checks out the package in a way that pres ...[truncated 1002 chars]
- An attacker creates a Skill package containing a symbolic link such as
- Remediation
View remediation
Remediation Suggestions
- Reject symbolic links before reading or inspecting package files:
python if script_file.is_symlink(): issues.append(Issue( level="error", message="Symbolic links are not allowed", file=str(script_file.relative_to(self.skill_path)), category="Script code", )) continue - Resolve every candidate path and verify that it remains under the resolved Skill root:
python root = self.skill_path.resolve() candidate = script_file.resolve(strict=True) if not candidate.is_relative_to(root): raise ValueError(f"Path escapes the Skill directory: {script_file}") - Apply the same containment validation before
read_text(),stat(), or any future file operation. - Open files defensively where supported, using no-follow semantics such as
O_NOFOLLOW, to reduce time-of-check/time-of-use races. - Check file size before reading full content and enforce a conservative maximum review size.
- Catch per-file
OSError, decoding, and permission errors so one hostile entry cannot terminate the complete audit.
- Reject symbolic links before reading or inspecting package files:
