Skip to content

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Jan 27, 2026

This reverts commit 3e90036.

Summary by Sourcery

Revert command whitelist validation for notification action execution to restore previous behavior.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts a previous change that added a safe-command whitelist check before executing notification action commands, restoring the prior behavior of executing the requested command directly without configuration-based validation.

Sequence diagram for executing notification action command without whitelist validation

sequenceDiagram
    actor User
    participant NotificationManager
    participant QProcess
    participant OperatingSystem

    User->>NotificationManager: actionInvoked(entity, actionKey)
    NotificationManager->>NotificationManager: parse entity and actionKey
    NotificationManager->>NotificationManager: extract command and arguments
    NotificationManager->>QProcess: configure program(cmd) and setArguments(args)
    NotificationManager->>QProcess: setProcessChannelMode
    NotificationManager->>QProcess: startDetached
    QProcess->>OperatingSystem: execute command with arguments
Loading

File-Level Changes

Change Details Files
Remove safe command whitelist validation for notification action commands, reverting to direct QProcess execution of the requested command.
  • Delete retrieval of the notification configuration (DConfig) used to load the list of safe commands.
  • Remove the safeCommands list lookup and membership check guarding command execution.
  • Restore the behavior where the first argument from the action data is executed directly via QProcess without validation against a whitelist.
panels/notification/server/notificationmanager.cpp
panels/notification/server/configs/org.deepin.dde.shell.notification.json

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Removing the safeCommands whitelist reintroduces the ability to execute arbitrary commands from notifications; if this revert is necessary, consider adding at least minimal validation or scoping of allowed binaries to mitigate security risk.
  • Since the command whitelist is no longer used, verify that any related configuration keys in org.deepin.dde.shell.notification are cleaned up or clearly deprecated to avoid confusion and dead config.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Removing the safeCommands whitelist reintroduces the ability to execute arbitrary commands from notifications; if this revert is necessary, consider adding at least minimal validation or scoping of allowed binaries to mitigate security risk.
- Since the command whitelist is no longer used, verify that any related configuration keys in org.deepin.dde.shell.notification are cleaned up or clearly deprecated to avoid confusion and dead config.

## Individual Comments

### Comment 1
<location> `panels/notification/server/notificationmanager.cpp:536-540` </location>
<code_context>
             if (!args.isEmpty()) {
                 QString cmd = args.takeFirst(); // 命令

-                QScopedPointer<DConfig> config(DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification"));
-                QStringList safeCommands = config->value("safeCommands").toStringList();
-
-                if (!safeCommands.contains(cmd)) {
-                    qWarning(notifyLog) << "The command is not allowed to be executed:" << cmd << safeCommands;
-                    return;
-                }
</code_context>

<issue_to_address>
**🚨 issue (security):** Removing the safeCommands allowlist introduces a potential command execution risk.

Without the `safeCommands` check, any `cmd` from the notification is passed to `QProcess`, which allows arbitrary command execution if `entity`/`args` can be influenced by untrusted input. Unless there is equivalent validation elsewhere, this is a security risk. Please reintroduce an allowlist or add strong validation to constrain which commands can be run.
</issue_to_address>

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.

Comment on lines -536 to -540
QScopedPointer<DConfig> config(DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification"));
QStringList safeCommands = config->value("safeCommands").toStringList();

if (!safeCommands.contains(cmd)) {
qWarning(notifyLog) << "The command is not allowed to be executed:" << cmd << safeCommands;
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Removing the safeCommands allowlist introduces a potential command execution risk.

Without the safeCommands check, any cmd from the notification is passed to QProcess, which allows arbitrary command execution if entity/args can be influenced by untrusted input. Unless there is equivalent validation elsewhere, this is a security risk. Please reintroduce an allowlist or add strong validation to constrain which commands can be run.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xionglinlin, yixinshark

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

@deepin-ci-robot
Copy link

deepin pr auto review

这是一个关于 DDE (Deepin Desktop Environment) 通知系统配置和源代码的变更审查。

审查总结

这次修改移除了通知系统中的“安全指令白名单”机制。具体来说,它删除了配置文件中的 safeCommands 定义,以及 C++ 代码中检查待执行命令是否在白名单内的逻辑。

结论:这是一个严重的安全风险变更(负向审查),建议驳回。


详细审查意见

1. 安全性 —— 极高风险

  • 任意命令执行漏洞
    • 原逻辑:代码通过 safeCommands 白名单机制,限制了 x-deepin-action 能够触发的命令。只有预定义在白名单中的命令(如 xdg-open, dde-file-manager 等)才允许被通知系统执行。这是一个有效的防御措施,防止恶意应用通过发送伪造的通知来执行任意系统命令。
    • 修改后:删除了白名单检查逻辑后,任何应用只要能发送 D-Bus 通知,就可以在用户点击通知时执行任意命令(例如 rm -rf ~ 或恶意脚本),只要该命令存在于系统的 PATH 中或提供了绝对路径。
    • 后果:这破坏了系统的最小权限原则,将系统暴露在严重的安全威胁之下。如果配合社会工程学诱导用户点击通知,攻击者可以轻易获取用户权限甚至系统权限。

2. 代码逻辑

  • 逻辑缺失
    • 原代码逻辑是:获取命令 -> 检查白名单 -> (通过) -> 执行
    • 修改后逻辑变为:获取命令 -> 执行
    • 删除检查逻辑导致防御层完全消失,且没有引入替代的验证机制(如沙箱、权限验证等)。

3. 代码质量

  • 冗余代码
    • NotificationManager::doActionInvoked 函数中,移除了白名单检查后,直接进入 QProcess 创建和执行流程。虽然代码行数减少了,但失去了关键的安全校验,属于“为了简洁而牺牲安全性”的反模式。

4. 代码性能

  • 性能提升微乎其微,得不偿失
    • 虽然移除 DConfig 的读取和 QStringListcontains 检查确实能减少极少的 CPU 开销(毫秒级),但相比于由此引入的严重安全漏洞,这种性能优化是完全不值得的。

改进建议

强烈建议恢复原有的白名单检查机制。

如果原实现存在问题(例如白名单更新不方便,或者某些合法命令被拦截),应该采取以下改进方式,而不是直接移除安全检查:

  1. 完善白名单机制

    • 如果某些应用需要执行特定命令,应将其路径或命令名正式加入 safeCommands 配置中,而不是移除配置。
    • 确保配置文件 org.deepin.dde.shell.notification.json 中的 safeCommands 是可维护的。
  2. 增强校验逻辑(如果确实需要更灵活的执行策略):

    • 可以考虑增加对命令参数的校验,防止命令注入。
    • 例如,只允许执行特定路径下的二进制文件,或者禁止包含管道符 (|)、重定向 (>) 等特殊字符的参数。
  3. 代码恢复示例

建议将代码恢复为类似以下形式(保留白名单检查):

void NotificationManager::doActionInvoked(const NotifyEntity &entity, const QString &actionKey)
{
    // ... 前面的代码 ...

    if (!args.isEmpty()) {
        QString cmd = args.takeFirst(); // 命令

        // --- 恢复安全检查 START ---
        QScopedPointer<DConfig> config(DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification"));
        if (config) {
            QStringList safeCommands = config->value("safeCommands").toStringList();
            // 建议增加对 cmd 路径的规范化处理,防止绕过 (例如 ./cmd 或 /usr/bin/../bin/cmd)
            if (!safeCommands.contains(cmd)) {
                qWarning(notifyLog) << "The command is not allowed to be executed:" << cmd << safeCommands;
                return;
            }
        } else {
            qWarning(notifyLog) << "Failed to load safe commands config, aborting action.";
            return;
        }
        // --- 恢复安全检查 END ---

        QProcess pro;
        pro.setProgram(cmd);
        pro.setArguments(args);
        // ... 执行代码 ...
    }
}

总结

该 Diff 移除了防止任意命令执行的关键安全屏障。请务必回滚此更改,并确保白名单机制正常工作。如果是为了解决功能兼容性问题,请通过扩充白名单或优化校验逻辑来解决,而不是移除校验。

@yixinshark
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jan 27, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit f3db087 into linuxdeepin:master Jan 27, 2026
8 of 11 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