Skip to content

fix(app): remove deprecated macOS root privilege escalation code with command injection risk - #132

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:fix/remove-macos-root-escalation
Sep 3, 2026
Merged

fix(app): remove deprecated macOS root privilege escalation code with command injection risk#132
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:fix/remove-macos-root-escalation

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Sep 2, 2026

Copy link
Copy Markdown

Summary

  • 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
  • Update SPDX copyright end year to 2026

修复内容

  • 移除 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,行为保持不变
  • SPDX 版权结束年份更新为 2026

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:

  • Remove deprecated macOS privilege-escalation code that could expose command-injection risk through unsanitized launch arguments.

Enhancements:

  • Make single-instance enforcement unconditional for the supported platform targets and remove obsolete macOS-specific code paths.

Chores:

  • Update the SPDX copyright end year to 2026.

… 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
@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Removes 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

Change Details Files
Removed the obsolete macOS privilege-escalation path and its command-injection exposure.
  • Deleted the Q_OS_MAC-only switchToRoot implementation that built an unescaped osascript shell command from process arguments.
  • Removed the main() invocation and now-unused QProcess include.
src/app/main.cpp
Made Linux single-instance initialization unconditional.
  • Removed the macOS preprocessor guard around the semaphore environment setting and single-instance check, preserving the existing behavior for supported Linux builds.
src/app/main.cpp
Updated source ownership metadata.
  • Changed the SPDX copyright end year from 2022 to 2026.
src/app/main.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次提交移除了存在命令注入风险(CWE-78)的废弃 macOS root 权限提升代码,消除了安全扫描报告中的 High 级告警,Linux 构建行为不变,代码清理干净彻底。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码变更语法正确,逻辑清晰。移除 switchToRoot() 函数及其调用点的操作完整一致,#include 的移除与函数移除配套,#ifndef Q_OS_MAC 条件编译守护的移除使得单实例检查在 Linux 上无条件执行,行为正确。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 本次变更移除了废弃的死代码(switchToRoot函数),清理了不再使用的 QProcess 头文件引用,简化了条件编译结构,更新了 SPDX 版权年份。PR 描述文档详尽,包含变更原因、影响分析和编译验证说明,代码质量优秀。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 移除 switchToRoot() 函数消除了 QProcess 进程创建开销(whoami 命令执行和 osascript 调用),单实例检查改为无条件执行对性能无影响。无性能问题。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 本次变更移除了存在命令注入风险(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 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77

Copy link
Copy Markdown
Author

/merge

@deepin-bot
deepin-bot Bot merged commit 08f405e into linuxdeepin:release/eagle Sep 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants