Skip to content

Commit 1fa62df

Browse files
LiHua000deepin-bot[bot]
authored andcommitted
fix: Fix path traversal vulnerability in zip extraction (bug #232873)
- Replace single-pass "../" removal with loop to remove all occurrences - Add final path validation to ensure extracted files stay within target directory Log: fix CITIVD Bug: https://pms.uniontech.com/bug-view-342883.html
1 parent efb5293 commit 1fa62df

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

3rdparty/libzipplugin/libzipplugin.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ ErrorType LibzipPlugin::extractEntry(zip_t *archive, zip_int64_t index, const Ex
796796
}
797797

798798
strFileName = m_common->trans2uft8(statBuffer.name, m_mapFileCode[index]); // 解压文件名(压缩包中)
799-
//fix 232873
800-
if(strFileName.indexOf("../") != -1) {
799+
//fix 232873 - Remove all "../" components to prevent path traversal attacks
800+
while(strFileName.contains("../")) {
801801
qInfo() << "skipped ../ path component(s) in " << strFileName;
802802
strFileName = strFileName.replace("../", "");
803803
}
@@ -895,6 +895,15 @@ ErrorType LibzipPlugin::extractEntry(zip_t *archive, zip_int64_t index, const Ex
895895
// 解压完整文件名(含路径)
896896
QString strDestFileName = options.strTargetPath + QDir::separator() + strFileName;
897897

898+
// Additional security check: ensure the final path is within the target directory
899+
QString cleanTargetPath = QDir::cleanPath(QDir(options.strTargetPath).absolutePath());
900+
QString cleanDestPath = QDir::cleanPath(QDir(strDestFileName).absolutePath());
901+
if (!cleanDestPath.startsWith(cleanTargetPath + QDir::separator()) &&
902+
cleanDestPath != cleanTargetPath) {
903+
qInfo() << "Path traversal detected! Rejected path: " << strFileName;
904+
return ET_FileWriteError;
905+
}
906+
898907
QFile file(strDestFileName);
899908

900909
// Store parent mtime.

0 commit comments

Comments
 (0)