fix(app): remove deprecated macOS root privilege escalation code with command injection risk - #132
Conversation
… command injection risk - Remove the unused switchToRoot() function guarded by Q_OS_MAC, which concatenated external argv into an osascript "do shell script ... with administrator privileges" string without escaping, posing a command injection risk (CWE-78) - Remove the switchToRoot() call site in main() and the unused QProcess include - Unwrap the single-instance check from #ifndef Q_OS_MAC since the code now only targets Linux, keeping behavior unchanged 修复(app): 移除已废弃的 macOS 提权代码,消除命令注入风险 - 移除 Q_OS_MAC 宏保护的 switchToRoot() 函数,该函数将外部启动参数未转义地拼接进 osascript "do shell script ... with administrator privileges" 字符串,存在命令注入 风险(CWE-78,安全扫描问题项 src/app/main.cpp:42) - 移除 main() 中的调用点及不再使用的 QProcess 头文件 - 单实例检查去除 #ifndef Q_OS_MAC 宏包裹,代码现仅面向 Linux,行为保持不变 Log: macOS 平台支持已于 2022 年随 commit 2ce7bb6 官方移除,此为残留死代码,删除后消除 AI 安全扫描报告的 High 级命令注入告警(CWE-78),Linux 构建行为不变,已编译验证 Bug: https://pms.uniontech.com/bug-view-375711.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRemoves unsupported macOS-only root escalation code and its command-injection risk, simplifies the single-instance path for the Linux-only application, and updates the SPDX copyright year; Linux behavior remains unchanged. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码变更语法正确,逻辑清晰。移除 switchToRoot() 函数及其调用点的操作完整一致,#include 的移除与函数移除配套,#ifndef Q_OS_MAC 条件编译守护的移除使得单实例检查在 Linux 上无条件执行,行为正确。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 本次变更移除了废弃的死代码(switchToRoot函数),清理了不再使用的 QProcess 头文件引用,简化了条件编译结构,更新了 SPDX 版权年份。PR 描述文档详尽,包含变更原因、影响分析和编译验证说明,代码质量优秀。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 移除 switchToRoot() 函数消除了 QProcess 进程创建开销(whoami 命令执行和 osascript 调用),单实例检查改为无条件执行对性能无影响。无性能问题。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 本次变更移除了存在命令注入风险(CWE-78)的 switchToRoot() 函数,该函数将外部启动参数未转义地拼接进 osascript "do shell script ... with administrator privileges" 字符串,存在命令注入风险。移除后代码无安全漏洞,安全合规。 💡 改进建议代码示例// 本次变更为代码删除操作,无需修复代码示例
// 移除的 switchToRoot() 函数存在命令注入风险(CWE-78)
// 正确做法即本次提交的操作:直接删除废弃的死代码
// 变更后的 main.cpp 关键部分:
// 1. 移除了 #include <QProcess>
// 2. 移除了 switchToRoot() 函数定义
// 3. 移除了 main() 中的 #ifdef Q_OS_MAC 调用点
// 4. 移除了 #ifndef Q_OS_MAC 单实例检查守护
// 5. 更新版权年份 2022 -> 2026
int main(int argc, char **argv)
{
// ... 初始化代码 ...
// 单实例检查(原 #ifndef Q_OS_MAC 守护已移除,无条件执行)
qputenv("DTK_USE_SEMAPHORE_SINGLEINSTANCE", "1");
if (!DGuiApplicationHelper::instance()->setSingleInstance(
app.applicationName(), DGuiApplicationHelper::UserScope)) {
exit(0);
}
// ... 后续代码不变 ...
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pppanghu77 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 |
|
/merge |
Summary
switchToRoot()function guarded byQ_OS_MAC, which concatenated external argv into an osascript "do shell script ... with administrator privileges" string without escaping, posing a command injection risk (CWE-78)switchToRoot()call site inmain()and the unusedQProcessinclude#ifndef Q_OS_MACsince the code now only targets Linux, keeping behavior unchanged修复内容
Q_OS_MAC宏保护的switchToRoot()函数,该函数将外部启动参数未转义地拼接进 osascript "do shell script ... with administrator privileges" 字符串,存在命令注入风险(CWE-78,安全扫描问题项 src/app/main.cpp:42)main()中的调用点及不再使用的QProcess头文件#ifndef Q_OS_MAC宏包裹,代码现仅面向 Linux,行为保持不变Impact
macOS 平台支持已于 2022 年随 commit 2ce7bb6 官方移除,此为残留死代码,删除后消除 AI 安全扫描报告的 High 级命令注入告警(CWE-78),Linux 构建行为不变,已编译验证。
Log: macOS 平台支持已于 2022 年随 commit 2ce7bb6 官方移除,此为残留死代码,删除后消除 AI 安全扫描报告的 High 级命令注入告警(CWE-78),Linux 构建行为不变,已编译验证
Bug: https://pms.uniontech.com/bug-view-375711.html
Summary by Sourcery
Remove obsolete macOS support remnants and retain Linux single-instance behavior while eliminating the associated command-injection risk.
Bug Fixes:
Enhancements:
Chores: