Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Zip Path Traversal vulnerability #72

Open
pwntester opened this issue Sep 4, 2018 · 1 comment
Open

Zip Path Traversal vulnerability #72

pwntester opened this issue Sep 4, 2018 · 1 comment

Comments

@pwntester
Copy link

The unzip APIs are vulnerable to a Zip entry path manipulation (see: https://snyk.io/research/zip-slip-vulnerability) . The library fails to check that the extracted file is going to be created under the destination folder.

A possible fix involves sanitizing the entry name returned by OZFileInZipInfo.name so that it does not contains ..

Also documentation should recommend normalizing the path before writing to disk:

OZZipFile *unzipFile= [[OZZipFile alloc] initWithFileName:@"test.zip"
    mode:OZZipFileModeUnzip];

[unzipFile goToFirstFileInZip];
OZFileInZipInfo *info= [unzipFile getCurrentFileInZipInfo];

OZZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:info.length];
[read readDataWithBuffer:data];

// Do something with data

[read finishedReading];

So adding something like:

NSString *fullName = [NSString stringWithFormat:@"%@/%@", destPath, entry.name];
    
NSString* normalizedName = [fullName stringByStandardizingPath];
if ([normalizedName hasPrefix:destPath]) {
       // extract
} else {
       // fail
}

Cheers,

A

@gianlucabertani
Copy link
Owner

Thanks for reporting. Will take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants