Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/dfm-io/dfm-io/denumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,17 @@ QUrl DEnumeratorPrivate::buildUrl(const QUrl &url, const char *fileName)
return QUrl();
}

// 拦截路径遍历攻击,防止恶意文件名越权
QByteArray fileNameBa(fileName);
if (fileNameBa.contains("../") || fileNameBa.contains("..\\") || fileNameBa.startsWith("..")) {
return QUrl();

// 路径遍历检查仅对本地文件系统 (file:/// 或无 scheme) 生效
// gio 的 trash:/// 后端对非用户主目录挂载点的回收站文件,使用反斜杠分隔的扁平路径
// 作为 GFileInfo 的 standard::name(例如 "\media\user\dev\.Trash-1000\files\x"),
// 这是合法的 trash 文件名而非恶意路径,故不应对其做路径遍历拦截。
const QString scheme = url.scheme();
if (scheme.isEmpty() || scheme == QLatin1String("file")) {
Comment on lines +391 to +392

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Consider restricting the relaxed check to specific non-local schemes instead of all non-file URLs

The current condition disables traversal checks for every non-empty, non-file scheme. For custom schemes that still map to filesystem-like backends, this could allow names with ../ or ..\ to pass unchecked. Since the need is specifically for trash:///, consider limiting the relaxed behavior to that scheme (or an explicit allowlist of schemes) rather than applying it to all non-file URLs.

if (fileNameBa.contains("../") || fileNameBa.contains("..\\") || fileNameBa.startsWith("..")) {
return QUrl();
}
}

QByteArray path;
Expand Down
Loading