Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
arbitrary file over write #453
Comments
|
And this library also supports symbolic link creation, which may cause security issue under certain circumstances |
|
Any update? |
|
AFAIK, supporting unrestricted parent path is a well-known feature in zip, tar or 7z protocol. don't understand why a zip library should handle this but indeed, lack of knowing this leads to unexpected things, thus arbitrary code execution. |
|
盘古的大神,你们应该是 宣传自己的安全工具吧 @turingH |
|
@fangli The best solution is checking script of security before runs it. |
|
fangli has a valid point. In my humble opinion I'd say we keep the original implementation as-is without extra filtering so as not to break backward compatibility, however we should probably implement new methods that explicitly handle the situation |
|
Agree with fangli. This is a feature, not a bug. |
|
@Naville 哪都能看见你 ^. ^ |
|
@turingH |
|
@SilverMoonSecurity but obviously this module doesn't provide such api, it just extract everything as is. |
|
The proposed fix in #456 is the right approach, I think. Overwriting files outside of the folder where the archive is getting unzipped is very unexpected (even if "valid" when it comes to what the zip format allows) and will surprise most users and developers, resulting in security issues. This is why most (if not all) popular archiving tool, such as the built-in tools on MacOS and Windows, do not support this behavior and never create files outside of the selected folder. The fix should make the library safe by default, with an option to override the security feature and restore the original behavior (which allows file overwrite). If you do it the other way around, none of the vulnerable apps will make the code change needed to enable security. |
|
2.1.3 released |
I'm a security researcher from pwnzen at Shanghai,China.
First of all, thank you for your sharing .
We found that
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination preserveAttributes:(BOOL)preserveAttributes overwrite:(BOOL)overwrite nestedZipLevel:(NSInteger)nestedZipLevel password:(nullable NSString *)password error:(NSError **)error delegate:(nullable id<SSZipArchiveDelegate>)delegate progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler { [...] if ([strPath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"/\\"]].location != NSNotFound) { strPath = [strPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]; } NSString *fullPath = [destination stringByAppendingPathComponent:strPath]; [...] }function may lead to arbitrary file over write
In case of holding path traversal filenames in the archive, strPath should be checked for whether it contains "../../../".