Skip to content

Commit abb6ead

Browse files
committed
Forbid tarballs with hard links being uploaded
It was discovered recently that tarballs with hard links aren't properly handled in the `tar` crate and can in malicious situations cause any file on the filesystem to get overwritten during the extraction process. This commit is a patch for crates.io to simply reject all tarballs which have hard links inside of them. This is a big hammer of a solution and is step 1 of a fix for this bug. I've verified that all existing tarballs on crates.io do not contain hard links and Cargo itself doesn't produce tarballs with hard links inside them. That means that no legitimate tarball should be rejected as a result of this patch. After this has been deployed I'll be updating the `tar` crate as well as Cargo itself, in addition to posting an announcement.
1 parent ef9e704 commit abb6ead

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/uploaders.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ fn verify_tarball(
271271
if !entry.path()?.starts_with(&prefix) {
272272
return Err(human("invalid tarball uploaded"));
273273
}
274+
275+
// Historical versions of the `tar` crate which Cargo uses internally
276+
// don't properly prevent hard links from overwriting arbitrary files on
277+
// the filesystem.
278+
//
279+
// As a bit of a hammer we reject any tarball with a hard link. Cargo
280+
// doesn't currently ever generate a tarball with a hard link so this
281+
// should work for now.
282+
if entry.header().entry_type().is_hard_link() {
283+
return Err(human("invalid tarball uploaded"));
284+
}
274285
}
275286
Ok(())
276287
}

0 commit comments

Comments
 (0)