Hmbown/CodeWhale · error
skill path escapes skills directory
Error message
skill path {} escapes skills directory {} What it means
ensure_target_within_skills_dir canonicalizes both the resolved skill target and the skills directory, and refuses if the target is not inside the skills dir. This is the final containment check that catches symlink- or '..'-based escapes before any file mutation happens.
Solutions
- Ensure the install target lives inside the skills directory
- Remove symlinks in the target chain that point outside the skills dir
- Verify the skills directory path is correct and not nested unexpectedly
Example fix
// before
target = skills_dir.join("link"); // link -> /tmp/elsewhere
// after
fs::remove_file(skills_dir.join("link"));
target = skills_dir.join("real-skill"); Defensive patterns
Strategy: validation
Validate before calling
let canon_target = std::fs::canonicalize(&target)?;
let canon_root = std::fs::canonicalize(&skills_dir)?;
if !canon_target.starts_with(&canon_root) {
return Err(anyhow!("target escapes skills directory"));
} Type guard
fn is_within(child: &Path, parent: &Path) -> std::io::Result<bool> {
Ok(std::fs::canonicalize(child)?.starts_with(std::fs::canonicalize(parent)?))
} Try / catch
match install_skill(...) {
Err(e) if e.to_string().contains("escapes skills directory") => eprintln!("install target resolved outside the skills dir; check for symlinks or '..' segments"),
other => other?,
} Prevention
- Avoid symlinks inside skill archives and target directories
- Canonicalize targets before planning installs
- Keep all skill content under the canonical skills root
When it happens
Trigger: Installing or importing a skill whose resolved target path (after canonicalization, including through symlinks) sorts outside the canonicalized skills directory.
Common situations: A skill archive containing a symlink pointing elsewhere; a target dir that is itself a symlink out of the skills tree; a manually misconfigured skills directory path.
Understand the failure class
Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.
Related errors
- audited skill path does not match owned package
- audited skill root identity changed; refusing mutation
- Codewhale-owned OAuth path escaped the credentials directory
- Codewhale-owned OAuth path has an invalid basename
- external credential path contains reparse point
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/6fed1a21c906c712.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/skills/install.rs:1567
bail!("skill name must be a single path-safe segment (got '{name}')");
}
if name == "." || name == ".." || name.contains('/') || name.contains('\\') {
bail!("skill name must be a single path-safe segment (got '{name}')");
}
let mut components = Path::new(name).components();
if !matches!(components.next(), Some(Component::Normal(_))) || components.next().is_some() {
bail!("skill name must be a single path-safe segment (got '{name}')");
}
Ok(name)
}
fn ensure_target_within_skills_dir(target: &Path, skills_dir: &Path) -> Result<()> {
let skills_dir = fs::canonicalize(skills_dir)
.with_context(|| format!("failed to resolve {}", skills_dir.display()))?;
let target = fs::canonicalize(target)
.with_context(|| format!("failed to resolve {}", target.display()))?;
if !target.starts_with(&skills_dir) {
bail!(
"skill path {} escapes skills directory {}",
target.display(),
skills_dir.display()
);
}
Ok(())
}
/// Strip a leading directory prefix (e.g. `repo-main/`) from a tarball path.
fn strip_prefix<'a>(path: &'a str, prefix: &str) -> std::borrow::Cow<'a, str> {
if prefix.is_empty() {
return std::borrow::Cow::Borrowed(path);
}
let with_slash = format!("{prefix}/");
if let Some(rest) = path.strip_prefix(&with_slash) {
std::borrow::Cow::Owned(rest.to_string())
} else if path == prefix {
std::borrow::Cow::Borrowed("")View on GitHub (pinned to 73e0f67d83)