jdx/mise · error · eyre::Report
too many symbolic links in managed directory
Error message
too many symbolic links in managed directory {} What it means
The managed-directory creation walks path components using openat with O_NOFOLLOW, tracking every symlink it must traverse. If more than 40 symlinks are followed along one path, it aborts with this error to break out of symlink loops or prohibitively deep symlink chains, protecting against infinite recursion (ELOOP-style) and malicious symlink attacks.
Solutions
- Inspect the path for symlink cycles with `namei <path>` or `readlink -f` and break the loop
- Reduce symlink indirection by targeting real directories
- Reconfigure the managed path to avoid traversing attacker- or misconfiguration-controlled symlinks
Example fix
// before
create_managed_dir(Path::new("/linked/loop/etc/app"))?; // /linked/loop points back through itself
// after
create_managed_dir(Path::new("/etc/app"))?; // real directory, no symlink chain Defensive patterns
Strategy: validation
Validate before calling
fn symlink_depth_ok(path: &std::path::Path) -> bool {
std::fs::canonicalize(path).is_ok() // canonicalize itself fails on loops
} Type guard
fn resolves_without_loop(path: &std::path::Path) -> bool {
path.canonicalize().is_ok()
} Try / catch
match result {
Err(e) if e.to_string().contains("too many symbolic links") => {
eprintln!("symlink loop or over-deep chain; inspect with namei");
}
other => other?,
} Prevention
- Run `namei -l <path>` on complex symlinked layouts before managed operations
- Avoid symlink cycles in deployment directories
- Keep symlink indirection shallow in tool-managed trees
When it happens
Trigger: Creating a managed directory under a path that contains a symlink cycle (e.g. /a -> /b, /b -> /a) or an unusually deep chain of symlinked directories (>40 hops).
Common situations: Misconfigured mount/symlink setups creating directory loops; chroot or overlay environments with recursive symlinks; intentionally deep symlinked directory structures.
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
- a parent directory is now a symlink; left untouched
- brew-cask: refusing elevated operation through mutable…
- brew-cask: refusing generic artifact source outside the…
- brew-cask: refusing generic artifact source outside the…
- brew-cask: refusing operation through untrusted directory
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/15da9ede819ae376.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/managed_files.rs:1650
/// Open an absolute directory path one component at a time without following
/// symlinks, creating missing components with process-default metadata. The
/// returned descriptor binds later metadata changes to the directory that was
/// actually opened instead of resolving the path again.
#[cfg(unix)]
fn open_or_create_directory_tree(path: &Path) -> Result<std::os::fd::OwnedFd> {
open_or_create_directory_tree_inner(path, 0)
}
#[cfg(unix)]
fn open_or_create_directory_tree_inner(
path: &Path,
followed_symlinks: usize,
) -> Result<std::os::fd::OwnedFd> {
use nix::fcntl::{AtFlags, OFlag, open, openat};
use nix::sys::stat::{Mode, SFlag, fstat, fstatat, mkdirat};
if followed_symlinks > 40 {
bail!(
"too many symbolic links in managed directory {}",
path.display()
);
}
let components = path
.strip_prefix(Path::new("/"))
.wrap_err_with(|| format!("managed directory must be absolute: {}", path.display()))?
.components()
.map(|component| match component {
std::path::Component::Normal(name) => Ok(name.to_os_string()),
_ => bail!("invalid managed directory path: {}", path.display()),
})
.collect::<Result<Vec<_>>>()?;
let flags = OFlag::O_RDONLY | OFlag::O_DIRECTORY | OFlag::O_NOFOLLOW;
let mut directory = open(Path::new("/"), flags, Mode::empty())?;
let mut current = PathBuf::from("/");View on GitHub (pinned to 533346cc37)