Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Jan 5, 2026

Summary by Sourcery

Restrict notification action command execution to a configurable safelist and integrate related configuration overrides into the shell build.

Bug Fixes:

  • Prevent execution of notification action commands that are not explicitly allowed in the notification configuration safelist.

Enhancements:

  • Introduce configuration entries for notification handling to define a safelist of allowed external commands.

Build:

  • Register and install Dtk configuration override files for the shell to support the new notification command safelist settings.

18202781743 and others added 2 commits January 5, 2026 18:23
1. Added installation of override configuration files in debian/dde-
shell.install
2. Updated CMakeLists.txt to install DTK preference override
configuration
3. Created new override file shell/overrides/
org.deepin.dtk.preference.json
4. The override file defines themeType configuration with proper
metadata including Chinese translations

Log: Added DTK preference override configuration for theme type settings

Influence:
1. Verify that the override configuration file is properly installed
to /usr/share/dsg/configs/overrides/org.deepin.dde.shell/
2. Test that theme type configuration is available through DTK
configuration system
3. Check that the themeType setting can be read and written correctly
4. Verify Chinese translations for configuration name and description
5. Ensure the configuration has proper permissions (readwrite) and
visibility (public)
6. Test that the override doesn't break existing configuration loading

fix: 添加DTK偏好设置覆盖配置

1. 在debian/dde-shell.install中添加覆盖配置文件的安装
2. 更新CMakeLists.txt以安装DTK偏好设置覆盖配置
3. 创建新的覆盖文件shell/overrides/org.deepin.dtk.preference.json
4. 覆盖文件定义了themeType配置,包含完整元数据和中文翻译

Log: 添加了主题类型设置的DTK偏好设置覆盖配置

Influence:
1. 验证覆盖配置文件是否正确安装到/usr/share/dsg/configs/overrides/
org.deepin.dde.shell/
2. 测试主题类型配置是否可通过DTK配置系统访问
3. 检查themeType设置能否正确读写
4. 验证配置名称和描述的中文翻译
5. 确保配置具有正确的权限(读写)和可见性(公开)
6. 测试覆盖配置不会破坏现有的配置加载

PMS: BUG-345091
Add safeCommands whitelist in dconfig with default safe commands
Validate commands against whitelist before execution

Log: add command whitelist validation for notification actions
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 Git diff 进行全面的代码审查:

  1. 代码逻辑和安全性改进:

在 notificationmanager.cpp 中的改进是很好的安全实践:

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;
}

优点:

  • 使用了白名单机制来限制可执行命令
  • 使用 DConfig 来管理配置,便于维护
  • 对不安全的命令有日志记录

建议改进:

  1. 可以考虑对命令路径进行规范化处理,防止路径遍历攻击

  2. 可以添加命令参数的验证,防止命令注入

  3. 建议将配置文件的读取操作缓存,避免每次都重新读取

  4. 配置文件改进:

在 org.deepin.dde.shell.notification.json 中添加的 safeCommands 配置项是合理的,但建议:

  1. 将配置项的 visibility 设为 "public",这样用户可以查看和了解哪些命令是允许的

  2. 可以考虑添加配置项的默认值说明

  3. 建议添加版本控制,方便后续更新

  4. 文件安装路径改进:

在 dde-shell.install 中的修改:

+usr/share/dsg/configs/overrides/org.deepin.dde.shell/*

这个改动是合理的,但建议:

  1. 确保覆盖配置文件的权限设置正确

  2. 考虑添加配置文件的备份机制

  3. CMakeLists.txt 改进:

添加的配置覆盖文件支持是好的实践,但建议:

  1. 添加错误处理机制,确保文件安装失败时有适当的提示

  2. 考虑添加配置文件的验证步骤

  3. 新增的 org.deepin.dtk.preference.json 文件:

这个配置文件结构合理,但建议:

  1. 添加配置项的取值范围说明
  2. 考虑添加配置项变更时的回调机制说明
  3. 可以添加配置项的默认值说明

总体建议:

  1. 添加更多的错误处理和日志记录
  2. 考虑添加配置项的验证机制
  3. 添加单元测试来验证新功能
  4. 考虑添加配置项的迁移机制,方便版本升级
  5. 建议添加配置文件的文档说明

这些改进主要关注了安全性、可维护性和用户体验,有助于提高代码质量和系统稳定性。

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a configurable safelist for notification action commands, enforcing it at execution time, and wires up DTK configuration/override metadata and packaging for dde-shell to ship the new settings.

Sequence diagram for safelisted notification action command execution

sequenceDiagram
    participant User
    participant NotificationUI
    participant NotificationManager
    participant DConfig
    participant QProcess

    User->>NotificationUI: Click notification action
    NotificationUI->>NotificationManager: doActionInvoked(entity, actionKey)
    activate NotificationManager
    NotificationManager->>NotificationManager: Parse action command and args
    NotificationManager->>DConfig: create(org.deepin.dde.shell, org.deepin.dde.shell.notification)
    DConfig-->>NotificationManager: DConfig instance
    NotificationManager->>DConfig: value(safeCommands)
    DConfig-->>NotificationManager: QStringList safeCommands
    NotificationManager->>NotificationManager: Check cmd in safeCommands
    alt Command not in safelist
        NotificationManager-->>NotificationManager: Log warning and return
    else Command allowed
        NotificationManager->>QProcess: setProgram(cmd)
        NotificationManager->>QProcess: setArguments(args)
        NotificationManager->>QProcess: start()
    end
    deactivate NotificationManager
Loading

Class diagram for NotificationManager safelist enforcement

classDiagram
    class NotificationManager {
        +void doActionInvoked(NotifyEntity entity, QString actionKey)
    }

    class DConfig {
        +static DConfig* create(QString appId, QString configName)
        +QVariant value(QString key)
    }

    class QProcess {
        +void setProgram(QString program)
        +void setArguments(QStringList arguments)
        +void start()
    }

    class NotifyEntity {
    }

    NotificationManager ..> DConfig : uses
    NotificationManager ..> QProcess : uses
    NotificationManager ..> NotifyEntity : parameter

    class SafeCommandPolicy {
        +QStringList safeCommands
        +bool isAllowed(QString cmd)
    }

    NotificationManager ..> SafeCommandPolicy : enforces

    SafeCommandPolicy : safeCommands loaded via DConfig safeCommands
    SafeCommandPolicy : deny execution if cmd not contained
Loading

File-Level Changes

Change Details Files
Enforce a safelist of allowed commands before executing notification action commands
  • Create a DConfig instance for org.deepin.dde.shell/org.deepin.dde.shell.notification when a notification action is invoked
  • Read the safeCommands string list from configuration
  • Abort command execution and log a warning if the requested command is not in the safelist
  • Proceed with QProcess execution only for safelisted commands
panels/notification/server/notificationmanager.cpp
panels/notification/server/configs/org.deepin.dde.shell.notification.json
Wire DTK config metadata and preference overrides into the build and runtime configuration
  • Register org.deepin.dde.shell DTK config override file in the CMake build using dtk_add_config_override_files
  • Add an overrides/org.deepin.dtk.preference.json file to define preference overrides for dde-shell
  • Ensure the new override file is installed via Debian packaging rules
shell/CMakeLists.txt
shell/overrides/org.deepin.dtk.preference.json
debian/dde-shell.install

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:

  • Creating a new DConfig instance on every action invocation may be expensive; consider caching the config object or the safeCommands list and updating it only when the configuration changes.
  • If safeCommands is empty, all commands will be blocked; double-check whether a missing/empty safelist should instead fall back to a default set or allow existing behavior to avoid surprising runtime failures.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Creating a new `DConfig` instance on every action invocation may be expensive; consider caching the config object or the `safeCommands` list and updating it only when the configuration changes.
- If `safeCommands` is empty, all commands will be blocked; double-check whether a missing/empty safelist should instead fall back to a default set or allow existing behavior to avoid surprising runtime failures.

## Individual Comments

### Comment 1
<location> `panels/notification/server/notificationmanager.cpp:535-536` </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)) {
</code_context>

<issue_to_address>
**issue (bug_risk):** Guard against DConfig::create failure and avoid dereferencing a null config pointer.

`DConfig::create` can return `nullptr` (e.g. backend failure or missing schema), so `config->value(...)` is a crash risk. Add a null check (e.g. `if (!config) { /* deny all commands + log */ }`) before calling `value()` and choose an appropriate fallback behaviour.
</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 +535 to +536
QScopedPointer<DConfig> config(DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification"));
QStringList safeCommands = config->value("safeCommands").toStringList();
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Guard against DConfig::create failure and avoid dereferencing a null config pointer.

DConfig::create can return nullptr (e.g. backend failure or missing schema), so config->value(...) is a crash risk. Add a null check (e.g. if (!config) { /* deny all commands + log */ }) before calling value() and choose an appropriate fallback behaviour.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy, 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

1 similar comment
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy, 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

@yixinshark yixinshark merged commit 4fb633a into linuxdeepin:release/deepin25.0.10 Jan 6, 2026
16 of 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.

4 participants