#2688·lf

Symlink race in file operations

Author: valoqCreated Sep 27, 2026Updated Sep 27, 2026

When lf copies, moves or renames files, it uses the path name and follows symlinks. The path is resolved at every step, which adds the potential of TOCTOU races. This has been attempted to be solved before in #2534

In most cases, this can result in accidentally following symlinks and files ending up where they were not supposed to. The risk depends on how often the user operates on files or in directories with symlinks.

There are two additional more severe cases:

  • When a user runs lf as root on files that are writable by a unprivileged user, this issue can lead to privilege escalation and its actually a well documented problem in file operations https://github.com/advisories/GHSA-xj38-jxc5-rppx
  • when the application runs chmod, this adds another vector to make this problem exploitable, which is why I consider this issue to be a blocker for #2678 which has to use chmod to preserve the permissions during copy

The "good" news for lf: nearly al file mangers have the same issue (including yazi and ranger) The only tool that I found to be safe is coreutils cp which has taken significant efforts to do this right

There is actually a lot to consider when it comes to file operations and making them reliably and ideally even secure, but I think following the example of coreutils is likely the right call.