jdx/mise · error

refusing cleanup through symlink component

Error message

refusing cleanup through symlink component {}

What it means

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.

Solutions

  1. Use a base image whose layout does not symlink the directories apk transients live under.
  2. Check which package created the symlink (per the path in the error) and remove/adjust it.
  3. If a legitimate package layout triggers this, file a mise issue so cleanup can whitelist it.
Defensive patterns

Strategy: try-catch

Try / catch

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; }

Prevention

When it happens

Trigger: `clean_apk_transients` -> `reject_symlink_components` finds `fs::symlink_metadata` reporting a symlink at an intermediate component of a cleanup target below the rootfs.

Common situations: Alpine packages that intentionally symlink directories (e.g. /lib -> usr/lib) colliding with cleanup paths; unusual base images with heavily symlinked layouts.

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


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/8b61388a2d837ad5. Report an issue: GitHub.

Appendix: source

Thrown at src/oci/packages.rs:562

    remove_path(&log)
}

/// Reject a cleanup target when it or any path component below `rootfs` is a
/// symlink. OCI package layers are untrusted, so following one during cleanup
/// could remove files outside the layer root.
fn reject_symlink_components(rootfs: &Path, target: &Path) -> Result<()> {
    let relative = target
        .strip_prefix(rootfs)
        .wrap_err_with(|| format!("cleanup target {} is outside rootfs", target.display()))?;
    let mut current = rootfs.to_path_buf();
    for component in relative.components() {
        let std::path::Component::Normal(component) = component else {
            bail!("invalid cleanup target {}", target.display());
        };
        current.push(component);
        match fs::symlink_metadata(&current) {
            Ok(metadata) if metadata.file_type().is_symlink() => {
                bail!(
                    "refusing cleanup through symlink component {}",
                    current.display()
                );
            }
            Ok(_) => {}
            Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(()),
            Err(err) => {
                return Err(err)
                    .wrap_err_with(|| format!("reading metadata for {}", current.display()));
            }
        }
    }
    Ok(())
}

/// Remove every regular file under `dir` (recursively), leaving the directory
/// structure and any symlinks intact. A missing `dir` is a no-op.
fn remove_files_recursively(dir: &Path) -> Result<()> {

View on GitHub (pinned to 533346cc37)