The name of an archive entry is joined to a directory without checking that the result stays inside it
What it finds
Entry names in a ZIP or TAR file are chosen by whoever made the archive; a name such as ../../app/config.json escapes the target directory when it is joined to it. After Path.GetFullPath, the result has to be checked to start with the target directory. The rule reports Path.Combine or Path.Join with an entry's FullName or Name in a method that never calls StartsWith; ExtractToDirectory, which checks by itself, is fine.
From the rule's source, archive_entry_path_traversal.rs.
using System.IO;using System.IO.Compression; class Unpacker{ void Extract(ZipArchive archive, string target) { foreach (var entry in archive.Entries) { entry.ExtractToFile(Path.Combine(target, entry.FullName));tx0 reports: the entry name may lead outside the target directory } }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:archive-entry-path-traversal" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:archive-entry-path-traversal] reason="..."tx0 explain tx0/csharp:archive-entry-path-traversal shows the same in the terminal. Found a false positive? Report it.