tar::Builder::append_dir_all() follows symlinks by default (follow = true). That behavior is documented, but the security issue is that dereferenced symlink targets are not checked against the source root passed to append_dir_all().
The function uses src_path as the logical archive boundary when building entry names:
let dest = path.join(src.strip_prefix(src_path).unwrap());but when reading from the filesystem, it follows symlinks through src.is_dir(), fs::read_dir(), fs::metadata(), and fs::File::open() without verifying that the resolved target still belongs to src_path.
This creates the core mismatch:
archive names are confined to
src_path, but file reads are not.
Affected: 0.4.11 through 0.4.46 inclusive
Patched: none
Current main: still affected as of 2c19ee2fbd01a306127e027cb05a02568ccda1b3
The range comes from the project history rather than guesswork:
Builder::append_dir_all()was added ina25da58f28f9e1648fe6bab46026c7ef412b1ebfon 2017-02-11 and merged before the0.4.11release.0.4.10predates the API.0.4.11was released on 2017-03-31, making it the first affected release.follow_symlinks(false)was added later in52a6f0f8833367771225bd9b742e6453eee1faacon 2017-06-30. It added an opt-out; the default remained symlink following.0.4.46was released on 2026-05-18. The preceding builder change1b4997cf5ef115f8d82680016c28490b5645b9c7was documentation-only and explicitly kept the existing behavior for compatibility.- No release or
maincommit after that adds source-root confinement toappend_dir_all()or changes the default away from symlink following.
Relevant history:
- https://github.com/composefs/tar-rs/commit/a25da58f28f9e1648fe6bab46026c7ef412b1ebf
- https://github.com/composefs/tar-rs/commit/52a6f0f8833367771225bd9b742e6453eee1faac
- https://github.com/composefs/tar-rs/commit/1b4997cf5ef115f8d82680016c28490b5645b9c7
- https://github.com/composefs/tar-rs/commit/fc459c149f83bf4daceaa52e17d351989002e1a9
All references below are pinned to commit:
2349b494827807791473f3c6ca9b2fc5ef274cdb
Builder::new() sets follow: true by default:
https://github.com/alexcrichton/tar-rs/blob/2349b494827807791473f3c6ca9b2fc5ef274cdb/src/builder.rs#L35-L46
follow_symlinks() states that symlink dereferencing defaults to true and compares the behavior to GNU tar --dereference / -h:
https://github.com/alexcrichton/tar-rs/blob/2349b494827807791473f3c6ca9b2fc5ef274cdb/src/builder.rs#L60-L67
The vulnerable flow is in append_dir_all():
https://github.com/alexcrichton/tar-rs/blob/2349b494827807791473f3c6ca9b2fc5ef274cdb/src/builder.rs#L920-L963
In this code path:
let dest = path.join(src.strip_prefix(src_path).unwrap());confines the archive entry name to src_path.
However, dereference mode then follows symlinks for filesystem reads:
if is_dir || (is_symlink && options.follow && src.is_dir()) {
for entry in fs::read_dir(&src)? {and:
let stat = fs::metadata(&src)?;
// ...
append_file(dst, &dest, &mut fs::File::open(src)?, options)?;There is no check that the resolved symlink target remains inside the original src_path.
An attacker who controls a directory archived by append_dir_all() can plant symlinks pointing outside that directory. The resulting archive can contain the target contents as normal files.
If the archiver runs with higher privileges than the attacker, this becomes a confused-deputy / privileged file disclosure issue: the attacker receives files they cannot read directly.
This is not about symlink dereference existing as a feature. The issue is dereference happening without root confinement.
Realistic affected patterns include:
- workspace export features
- backup jobs
- CI artifact packaging
- build systems that package user-controlled directories
- services that archive user-uploaded or user-writable trees
root/ <- directory passed to append_dir_all()
leak.txt -> /tmp/ghsa_privdir/secret.txt
/tmp/ghsa_privdir/secret.txt
owned by root
mode 0400
The unprivileged user cannot read the file directly:
cat /tmp/ghsa_privdir/secret.txt
# Permission deniedA privileged export worker runs the normal tar-rs flow:
let f = File::create("/tmp/ghsa_export.tar")?;
let mut b = tar::Builder::new(f);
// default: follow_symlinks(true)
b.append_dir_all("", user_controlled_root)?;
b.finish()?;The unprivileged user can read the root-only file from the generated archive:
tar -xOf /tmp/ghsa_export.tar leak.txt
ROOT_ONLY_SECRET_1776952887This proves that append_dir_all() can turn a symlink inside an attacker-controlled tree into a read of a privileged out-of-root file.
A directory symlink also works:
ln -s /tmp/ghsa_privdir "$WORK/escape_dir"
tar -xOf /tmp/ghsa_export.tar escape_dir/secret.txt
ROOT_ONLY_SECRET_1776952887That means one planted directory symlink can expose an external readable tree, not only a single known file.
The downstream wrapper does not introduce a project-specific bug. The vulnerable pattern is only:
Builder::new(writer).append_dir_all("", user_controlled_root)The root cause is in tar-rs: src_path is enforced for archive entry naming, but not for filesystem reads after symlink resolution.
Compatibility may affect how the behavior is fixed, but it does not make the issue downstream-only. Affected users still need a crate-level security signal telling them not to use the default behavior for untrusted source trees.
Callers archiving untrusted trees should disable symlink following:
let mut b = tar::Builder::new(writer);
b.follow_symlinks(false);
b.append_dir_all("", untrusted_root)?;
b.finish()?;With follow_symlinks(false), symlinks are stored as symlink entries instead of being read through and embedded as regular files.