fix(read.go): arbitrary file access during archive extraction zipslip
https://github.com/NVIDIA/aistore/blob/102b5d92152372f976720a23668b9d7c2948778a/cmn/archive/read.go#L266-L287
Fix the issue need to sanitize the file paths extracted from the zip archive to prevent directory traversal attacks. Specifically, we should ensure that the f.FileHeader.Name does not contain any .. elements or other malicious patterns that could lead to writing files outside the intended directory. This can be achieved by:
- Using
filepath.Cleanto normalize the path. - Verifying that the resulting path is within the intended extraction directory.
- Rejecting or skipping any entries that fail these checks.
The fix will be applied in the ReadUntil and ReadOne methods of the zipReader struct in cmn/archive/read.go.
-
Good catch.
-
The scope. There's not only zip, there are other archival readers, including tar. The same exact concern applies wrt directory traversals. There must be a single piece of code used by all archival readers.
-
filepath.Cleanis uncalled for. In fact,filepath.Cleancan hide some of those path mutations and introduce false negatives. The "../" in the path is illegal - period, end of story.
Secondly and separately, filepath.Clean is slow, and you don't want it in the datapath. And finally,
- We already have
cmn.ValidateOname- maybe use it.
thank you for your contribution; this is now implemented differently but still - thanks a lot!