{"record":{"id":"8b61388a2d837ad5","repo":"jdx/mise","slug":"refusing-cleanup-through-symlink-component","errorCode":null,"errorMessage":"refusing cleanup through symlink component {}","messagePattern":"refusing cleanup through symlink component (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/oci/packages.rs","lineNumber":562,"sourceCode":"    remove_path(&log)\n}\n\n/// Reject a cleanup target when it or any path component below `rootfs` is a\n/// symlink. OCI package layers are untrusted, so following one during cleanup\n/// could remove files outside the layer root.\nfn reject_symlink_components(rootfs: &Path, target: &Path) -> Result<()> {\n    let relative = target\n        .strip_prefix(rootfs)\n        .wrap_err_with(|| format!(\"cleanup target {} is outside rootfs\", target.display()))?;\n    let mut current = rootfs.to_path_buf();\n    for component in relative.components() {\n        let std::path::Component::Normal(component) = component else {\n            bail!(\"invalid cleanup target {}\", target.display());\n        };\n        current.push(component);\n        match fs::symlink_metadata(&current) {\n            Ok(metadata) if metadata.file_type().is_symlink() => {\n                bail!(\n                    \"refusing cleanup through symlink component {}\",\n                    current.display()\n                );\n            }\n            Ok(_) => {}\n            Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(()),\n            Err(err) => {\n                return Err(err)\n                    .wrap_err_with(|| format!(\"reading metadata for {}\", current.display()));\n            }\n        }\n    }\n    Ok(())\n}\n\n/// Remove every regular file under `dir` (recursively), leaving the directory\n/// structure and any symlinks intact. A missing `dir` is a no-op.\nfn remove_files_recursively(dir: &Path) -> Result<()> {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/oci/packages.rs#L544-L580","documentation":"While cleaning apk transient files, mise walks each path component and refuses to proceed if an intermediate component is a symlink, preventing cleanup from following a link outside (or into unexpected parts of) the rootfs. This is a deliberate symlink-attack guard.","triggerScenarios":"`clean_apk_transients` -> `reject_symlink_components` finds `fs::symlink_metadata` reporting a symlink at an intermediate component of a cleanup target below the rootfs.","commonSituations":"Alpine packages that intentionally symlink directories (e.g. /lib -> usr/lib) colliding with cleanup paths; unusual base images with heavily symlinked layouts.","solutions":["Use a base image whose layout does not symlink the directories apk transients live under.","Check which package created the symlink (per the path in the error) and remove/adjust it.","If a legitimate package layout triggers this, file a mise issue so cleanup can whitelist it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await miseOciBuild(cfg) } catch (e) { if (String(e).includes('refusing cleanup through symlink component')) { console.error('Base image layout symlinks a cleanup path; use a standard Alpine/Wolfi base.'); process.exit(1); } throw e; }","preventionTips":["Prefer standard Alpine/Wolfi base images with conventional directory layouts.","Avoid packages that symlink system directories referenced by cleanup (e.g. /lib).","File a mise issue if a legitimate package layout trips the guard."],"tags":["security","symlink","oci","cleanup"],"backgroundTag":"path-traversal-blocked","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}