GHSA-j4xf-2g29-59ph

Suggest an improvement
Source
https://github.com/advisories/GHSA-j4xf-2g29-59ph
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-j4xf-2g29-59ph/GHSA-j4xf-2g29-59ph.json
JSON Data
https://api.test.osv.dev/v1/vulns/GHSA-j4xf-2g29-59ph
Aliases
Related
Published
2026-03-20T17:25:09Z
Modified
2026-03-23T19:29:13.465622Z
Severity
  • 5.1 (Medium) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N CVSS Calculator
Summary
tar-rs `unpack_in` can chmod arbitrary directories by following symlinks
Details

Summary

When unpacking a tar archive, the tar crate's unpack_dir function uses fs::metadata() to check whether a path that already exists is a directory. Because fs::metadata() follows symbolic links, a crafted tarball containing a symlink entry followed by a directory entry with the same name causes the crate to treat the symlink target as a valid existing directory — and subsequently apply chmod to it. This allows an attacker to modify the permissions of arbitrary directories outside the extraction root.

Reproducer

A malicious tarball contains two entries: (1) a symlink foo pointing to an arbitrary external directory, and (2) a directory entry foo/. (or just foo). When unpacked, create_dir("foo") fails with EEXIST because the symlink is already on disk. The fs::metadata() check then follows the symlink, sees a directory at the target, and allows processing to continue. The directory entry's mode bits are then applied via chmod, which also follows the symlink — modifying the permissions of the external target directory.

Fix

The fix is very simple, we now use fs::symlink_metadata() in unpack_dir, so symlinks are detected and rejected rather than followed.

Credit

This issue was reported by @xokdvium - thank you!

Database specific
{
    "severity": "MODERATE",
    "nvd_published_at": "2026-03-20T08:16:11Z",
    "cwe_ids": [
        "CWE-61"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-03-20T17:25:09Z"
}
References

Affected packages

crates.io / tar

Package

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
0.4.45

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-j4xf-2g29-59ph/GHSA-j4xf-2g29-59ph.json"
last_known_affected_version_range
"<= 0.4.44"