fix: add path traversal check in mkTempDir function#191
fix: add path traversal check in mkTempDir function#191deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
- Implemented a validation check in the mkTempDir function to reject infix values containing "..", enhancing security against path traversal vulnerabilities. This change improves the robustness of the temporary directory creation process.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a security-focused validation to Utils::mkTempDir to reject potentially unsafe infix values that contain path traversal sequences before constructing the temporary directory path. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Sorry @dengzhongyuan365-dev, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
deepin pr auto review这段代码的修改旨在增加安全性,防止路径遍历攻击。以下是对该代码变更的详细审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码示例QString Utils::mkTempDir(const QString &infix)
{
qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix;
// 检查空输入
if (infix.isEmpty()) {
qWarning() << "Utils::mkTempDir - Empty infix";
return QString();
}
// 检查路径遍历和绝对路径
if (infix.contains("..") || infix.startsWith('/') || infix.contains('\0')) {
qWarning() << "Utils::mkTempDir - Invalid infix contains path traversal or absolute path:" << infix;
return QString();
}
// 检查字符集(可选)
QRegularExpression safeChars("^[a-zA-Z0-9_-]+$");
if (!safeChars.match(infix).hasMatch()) {
qWarning() << "Utils::mkTempDir - Invalid infix contains unsafe characters:" << infix;
return QString();
}
// Construct template like "/var/tmp/diskmanager-XXXXXX" or "/var/tmp/diskmanager-INFIX-XXXXXX"
QString dirTemplate = "/var/tmp/";
// ... 其余代码
}总结
通过以上改进,可以显著提高代码的安全性和健壮性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
This change improves the robustness of the temporary directory creation process.
Summary by Sourcery
Bug Fixes: