{"record":{"id":"6fed1a21c906c712","repo":"Hmbown/CodeWhale","slug":"skill-path-escapes-skills-directory","errorCode":null,"errorMessage":"skill path {} escapes skills directory {}","messagePattern":"skill path (.+?) escapes skills directory (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/skills/install.rs","lineNumber":1567,"sourceCode":"        bail!(\"skill name must be a single path-safe segment (got '{name}')\");\n    }\n    if name == \".\" || name == \"..\" || name.contains('/') || name.contains('\\\\') {\n        bail!(\"skill name must be a single path-safe segment (got '{name}')\");\n    }\n    let mut components = Path::new(name).components();\n    if !matches!(components.next(), Some(Component::Normal(_))) || components.next().is_some() {\n        bail!(\"skill name must be a single path-safe segment (got '{name}')\");\n    }\n    Ok(name)\n}\n\nfn ensure_target_within_skills_dir(target: &Path, skills_dir: &Path) -> Result<()> {\n    let skills_dir = fs::canonicalize(skills_dir)\n        .with_context(|| format!(\"failed to resolve {}\", skills_dir.display()))?;\n    let target = fs::canonicalize(target)\n        .with_context(|| format!(\"failed to resolve {}\", target.display()))?;\n    if !target.starts_with(&skills_dir) {\n        bail!(\n            \"skill path {} escapes skills directory {}\",\n            target.display(),\n            skills_dir.display()\n        );\n    }\n    Ok(())\n}\n\n/// Strip a leading directory prefix (e.g. `repo-main/`) from a tarball path.\nfn strip_prefix<'a>(path: &'a str, prefix: &str) -> std::borrow::Cow<'a, str> {\n    if prefix.is_empty() {\n        return std::borrow::Cow::Borrowed(path);\n    }\n    let with_slash = format!(\"{prefix}/\");\n    if let Some(rest) = path.strip_prefix(&with_slash) {\n        std::borrow::Cow::Owned(rest.to_string())\n    } else if path == prefix {\n        std::borrow::Cow::Borrowed(\"\")","sourceCodeStart":1549,"sourceCodeEnd":1585,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/skills/install.rs#L1549-L1585","documentation":"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.","triggerScenarios":"Installing or importing a skill whose resolved target path (after canonicalization, including through symlinks) sorts outside the canonicalized skills directory.","commonSituations":"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.","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"],"exampleFix":"// before\ntarget = skills_dir.join(\"link\"); // link -> /tmp/elsewhere\n// after\nfs::remove_file(skills_dir.join(\"link\"));\ntarget = skills_dir.join(\"real-skill\");","handlingStrategy":"validation","validationCode":"let canon_target = std::fs::canonicalize(&target)?;\nlet canon_root = std::fs::canonicalize(&skills_dir)?;\nif !canon_target.starts_with(&canon_root) {\n    return Err(anyhow!(\"target escapes skills directory\"));\n}","typeGuard":"fn is_within(child: &Path, parent: &Path) -> std::io::Result<bool> {\n    Ok(std::fs::canonicalize(child)?.starts_with(std::fs::canonicalize(parent)?))\n}","tryCatchPattern":"match install_skill(...) {\n    Err(e) if e.to_string().contains(\"escapes skills directory\") => eprintln!(\"install target resolved outside the skills dir; check for symlinks or '..' segments\"),\n    other => other?,\n}","preventionTips":["Avoid symlinks inside skill archives and target directories","Canonicalize targets before planning installs","Keep all skill content under the canonical skills root"],"tags":["path-traversal","security","skills"],"backgroundTag":"path-traversal-blocked","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}