{"record":{"id":"3897b7825fd6c5ce","repo":"jdx/mise","slug":"invalid-cleanup-target","errorCode":null,"errorMessage":"invalid cleanup target {}","messagePattern":"invalid cleanup target (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/oci/packages.rs","lineNumber":557,"sourceCode":"    let cache = rootfs.join(\"var/cache/apk\");\n    let log = rootfs.join(\"var/log/apk.log\");\n    reject_symlink_components(rootfs, &cache)?;\n    reject_symlink_components(rootfs, &log)?;\n    remove_dir_children(&cache)?;\n    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(())","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/oci/packages.rs#L539-L575","documentation":"During post-install cleanup of apk transients, `reject_symlink_components` re-validates each cleanup target path relative to the rootfs. Any component that is not a plain `Normal` component (e.g. `..`, `/`, or a prefix) makes the target unsafe, so mise bails with this error.","triggerScenarios":"`clean_apk_transients` computes a cleanup path whose relative form against the rootfs contains non-normal components — essentially a malformed or escaping path reaching the cleanup stage.","commonSituations":"Corrupted or hand-edited apk database paths; unusual symlinks/paths produced by a broken package; a mise internal bug rather than user configuration.","solutions":["Inspect the apk database/installed paths inside the rootfs for malformed entries and repair them.","Rebuild from a clean, known-good Alpine/Wolfi base image.","If reproducible with a normal config, file a mise bug with the config and base image details."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await miseOciBuild(cfg) } catch (e) { if (String(e).includes('invalid cleanup target')) { console.error(' apk database produced a malformed path; rebuild from a clean base image.'); process.exit(1); } throw e; }","preventionTips":["Use official, unmodified Alpine/Wolfi base images.","Avoid hand-editing the rootfs or apk database between build steps.","Report reproducible occurrences to mise as a bug with config and base image."],"tags":["security","path-validation","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"}