Skip to content

Also need to strip off leading / characters to sanitize zip entry paths #20

@lukehutch

Description

@lukehutch

Zip paths are not supposed to start with a slash, but in theory they can -- you can put anything you want in the zip entry name. In most cases, two slashes in a row in a path will just be interpreted as a single slash, but it is highly likely that a great deal of library routines out there that resolve a zip entry path relative to a base path will treat a zip entry path with a leading / as an absolute path, and ignore the base path during path resolution. Therefore, all the info on the ZipSlip repository should also strip off leading / characters.

You also can't just strip off a single leading /, in case there are two leading / characters. So something like the following is needed:

while (zipEntryPath.startsWith("/")) {
    zipEntryPath = zipEntryPath.substring(1);
}

For reference, my fix for this issue and the standard Zip Slip issue in FastClasspathScanner is here:

classgraph/classgraph@93910ad

In an even more esoteric case, on Windows, it's possible that some library routines that resolve a relative path, relative to a base path, may interpret a path starting with a drive designation as an absolute path, e.g. c:/Windows/System32. Probably this should be protected against too, just to make things more complicated...

I remember first hearing about Zip Slip (though it didn't have a name at the time) more than 20 years ago. I'm surprised this has not been more widely known before now, but I'm glad you're working to change that, and get all the broken code fixed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions