Heuristic:AMAP ML SkillClaw Path Safety Validation
| Knowledge Sources | |
|---|---|
| Domains | Debugging, Security |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Path safety validation for skill bundles that prevents directory traversal attacks by rejecting absolute paths, parent-directory references (`..`), and Windows drive letters in bundle relative paths.
Description
The `normalize_bundle_rel_path` function validates every relative path in a skill bundle before it is written to disk. It rejects: (1) empty paths, (2) absolute POSIX paths (`/`), (3) absolute Windows paths (`C:\`), (4) Windows drive letters, (5) path components containing `..`, `.`, or empty strings. The `normalize_skill_path_segment` function adds additional validation for skill names and categories — it rejects null bytes, multi-segment paths, and `.`/`..` segments. The `write_skill_bundle` function adds a final defense: it resolves each planned write path and checks it stays within the skill directory root (`.resolve().relative_to(root_resolved)`), raising `SkillBundleError` if a path escapes.
Usage
Use this heuristic when writing skill bundles from untrusted sources (e.g., downloaded from shared storage or agent-generated). It prevents path traversal attacks that could overwrite system files. Applied automatically by `skill_bundle.py` functions and `SkillHub` during pull/push operations.
The Insight (Rule of Thumb)
- Action: Validate every bundle path with `normalize_bundle_rel_path`; validate skill names with `normalize_skill_path_segment`; verify resolved paths stay within root in `write_skill_bundle`.
- Value: Reject: empty, absolute, `..`, `.`, Windows drive, null bytes, multi-segment names.
- Trade-off: Slight overhead per path validation, but prevents file system traversal vulnerabilities.
- Compatibility: Cross-platform — checks both POSIX and Windows path formats.
Reasoning
Skill bundles are downloaded from shared object storage (S3/OSS) where a malicious actor could craft a bundle with paths like `../../etc/cron.d/evil`. Without validation, `write_skill_bundle` would write files outside the intended skill directory. The multi-layer defense (normalize → coerce → resolve check) ensures that even if one check is bypassed, the final path resolution catch prevents directory escape. Checking both POSIX and Windows path formats prevents attacks that exploit OS-specific path handling.
Code Evidence
Path normalization from `skillclaw/skill_bundle.py:29-42`:
def normalize_bundle_rel_path(rel_path: str) -> str:
value = str(rel_path or "").strip().replace("\\", "/")
if not value:
raise SkillBundleError("Bundle path must not be empty")
posix_path = PurePosixPath(value)
windows_path = PureWindowsPath(value)
if posix_path.is_absolute() or windows_path.is_absolute() or windows_path.drive:
raise SkillBundleError(f"Bundle path must be relative: {rel_path!r}")
parts = posix_path.parts
if not parts:
raise SkillBundleError("Bundle path must not be empty")
if any(part in {"", ".", ".."} for part in parts):
raise SkillBundleError(f"Unsafe bundle path: {rel_path!r}")
return "/".join(parts)
Skill name validation from `skillclaw/skill_bundle.py:45-58`:
def normalize_skill_path_segment(value: str, field: str) -> str:
segment = str(value or "").strip()
normalized = segment.replace("\\", "/")
windows_path = PureWindowsPath(normalized)
if (
not segment
or "\x00" in segment
or windows_path.drive
or len(PurePosixPath(normalized).parts) != 1
or segment in {".", ".."}
):
raise SkillBundleError(f"Unsafe {field}: {value!r}")
return segment
Write-time path escape check from `skillclaw/skill_bundle.py:169-177`:
for rel_path, data in sorted(coerce_skill_bundle(bundle_files).items()):
path = root / Path(rel_path)
try:
path.resolve(strict=False).relative_to(root_resolved)
except ValueError as exc:
raise SkillBundleError(f"Bundle path escapes skill directory: {rel_path!r}") from exc
planned_writes.append((path, data))