-
Notifications
You must be signed in to change notification settings - Fork 34
fix: add path traversal check in mkTempDir function #193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -661,6 +661,14 @@ bool Utils::kernelSupportFS(const QString &fsType) | |
|
|
||
| QString Utils::mkTempDir(const QString &infix) | ||
| { | ||
| qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix; | ||
|
|
||
| // 路径遍历检查:拒绝包含 ".." 的 infix | ||
| if (infix.contains("..")) { | ||
| qWarning() << "Utils::mkTempDir - Invalid infix contains path traversal:" << infix; | ||
| return QString(); | ||
|
Comment on lines
+667
to
+669
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 suggestion (security): Path traversal mitigation likely also needs to handle slashes and absolute paths Rejecting ".." is helpful, but infix values that include path separators ("/" or "\") or start with a slash could still affect the final path, depending on how dirTemplate and infix are combined. To avoid mkTempDir escaping the intended base directory, also reject any path separators and leading slashes, or restrict infix to a filename-like pattern (e.g., alphanumerics, dash, underscore). |
||
| } | ||
|
|
||
| // Construct template like "/var/tmp/diskmanager-XXXXXX" or "/var/tmp/diskmanager-INFIX-XXXXXX" | ||
| QString dirTemplate = "/var/tmp/"; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Consider avoiding unconditional qDebug noise in a frequently used utility
Since this helper is used in many places, an unconditional qDebug here could generate excessive logs in normal runs. If this is for troubleshooting, consider guarding it behind a debug/verbose flag or moving the logging to a higher-level caller that invokes mkTempDir.