Skip to content

sync: from linuxdeepin/dde-session-shell - #559

Open
deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-106-nosync
Open

deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-106-nosync

Conversation

@deepin-ci-robot

@deepin-ci-robot deepin-ci-robot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#106

Summary by Sourcery

Harden session-shell security and process execution while removing sensitive authentication data from logs.

Bug Fixes:

  • Restrict lock-screen suspend requests to callers running under the current user, rejecting unauthorized or unresolvable callers.
  • Prevent authentication and encryption operations from proceeding when required keys are unavailable.
  • Replace shell-based command execution with direct process invocation for keyboard ungrabbing, display wake-up, monitor detection, and PAM auto-login handling.
  • Stop logging authentication tokens in session widget diagnostics.

Enhancements:

  • Improve keyboard, display, and PAM process handling while preserving existing authentication and screen-management behavior.

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#106
@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Synchronizes security and robustness changes from dde-session-shell: authorizes suspend requests by Unix UID, removes shell-mediated process execution in several paths, hardens encryption key failures, and stops logging authentication tokens.

Sequence diagram for authorized suspend requests

sequenceDiagram
    participant Caller
    participant DBusLockAgent
    participant DBus
    participant SessionShell

    Caller->>DBusLockAgent: Suspend(enable)
    DBusLockAgent->>DBusLockAgent: getCallerBySender()
    DBusLockAgent->>DBus: GetConnectionUnixUser(caller)
    DBus-->>DBusLockAgent: callerUid
    alt callerUid matches getuid()
        DBusLockAgent->>SessionShell: process suspend request
    else unauthorized or UID lookup fails
        DBusLockAgent-->>Caller: reject request
    end
Loading

Flow diagram for shell-free keyboard ungrab

flowchart LR
    A[ungrabKeyboard] --> B[QProcess start setxkbmap -query]
    B --> C[Read current option]
    C --> D[QProcess execute setxkbmap -option grab:break_actions]
    D --> E[QProcess execute xdotool key XF86Ungrab]
    E --> F[QProcess execute setxkbmap -option originmap]
Loading

Flow diagram for PAM autologin inhibition

flowchart LR
    A[pam_sm_authenticate] --> B{Shell script exists?}
    B -- no --> C[PAM_SUCCESS]
    B -- yes --> D[fork]
    D --> E[Child: execl shell script]
    E --> F[Parent: waitpid]
    F --> G{Exit status is zero?}
    G -- yes --> H[PAM_PERM_DENIED]
    G -- no --> I[PAM_SUCCESS]
Loading

File-Level Changes

Change Details Files
Restrict the lock agent’s suspend D-Bus operation to callers running under the same Unix UID.
  • Resolve the D-Bus sender’s Unix UID through the session bus.
  • Reject unauthorized, missing, or unresolvable callers and log the decision before suspend handling.
src/dde-lock/dbus/dbuslockagent.cpp
src/dde-lock/dbus/dbuslockagent.h
Replace shell-command pipelines and shell invocation with direct process APIs for keyboard and display management.
  • Query and restore keyboard options using QProcess arguments while issuing the ungrab action directly.
  • Trigger display wake-up with detached xset execution.
  • Execute the PAM autologin hook via fork/exec and waitpid with explicit exit-status handling.
  • Run xrandr directly and filter connected displays in process output.
src/global_util/keyboardmonitor/keyboardplantform_wayland.cpp
src/libdde-auth/deepinauthframework.cpp
src/pam-inhibit-autologin/pam_inhibit_autologin.c
src/widgets/fullscreenbackground.cpp
Add defensive checks around encryption key initialization and encryption operations.
  • Log missing RSA or EC public keys during initialization.
  • Fail early with an empty result when the selected encryption key is unavailable.
src/libdde-auth/encrypt_helper.cpp
Remove authentication-token values from informational logs.
  • Keep account and authentication-flow context while omitting password, custom-auth, and token contents from log messages.
src/session-widgets/assist_login_widget.cpp
src/session-widgets/sfa_widget.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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dde-lock/dbus/dbuslockagent.cpp" line_range="204" />
<code_context>
+        return true;
+    }
+
+    QString caller = msg.service();
+    if (caller.isEmpty()) {
+        return false;
</code_context>
<issue_to_address>
**Caller UID check uses destination**

When a caller running as a different user can send a method call to the lock service, `msg.service()` identifies the method-call destination, not its sender, so `GetConnectionUnixUser` checks the lock service’s UID and accepts a caller running as another user. That caller can invoke `Suspend(false)` and hide the lock screen when suspend locking is disabled.

Use the incoming message’s sender identity (for example, `msg.sender()`) for the UID lookup, and reject the call unless that sender’s UID matches the intended user.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

return true;
}

QString caller = msg.service();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Caller UID check uses destination

When a caller running as a different user can send a method call to the lock service, msg.service() identifies the method-call destination, not its sender, so GetConnectionUnixUser checks the lock service’s UID and accepts a caller running as another user. That caller can invoke Suspend(false) and hide the lock screen when suspend locking is disabled.

Use the incoming message’s sender identity (for example, msg.sender()) for the UID lookup, and reject the call unless that sender’s UID matches the intended user.

Prompt for AI agents
In `src/dde-lock/dbus/dbuslockagent.cpp` at line 204:

**Caller UID check uses destination**

When a caller running as a different user can send a method call to the lock service, `msg.service()` identifies the method-call destination, not its sender, so `GetConnectionUnixUser` checks the lock service’s UID and accepts a caller running as another user. That caller can invoke `Suspend(false)` and hide the lock screen when suspend locking is disabled.

Use the incoming message’s sender identity (for example, `msg.sender()`) for the UID lookup, and reject the call unless that sender’s UID matches the intended user.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为安全加固同步,将多处 system() 调用替换为 QProcess/fork+execl 等安全替代方案,新增 DBus 调用者 UID 鉴权检查,为加密密钥添加空指针防御,并从日志中移除 token 敏感信息。所有变更均为正面安全改进,未引入新漏洞,语法逻辑正确,性能无回退。仅 isCallerAuthorized 函数缺少函数级注释。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: ['建议在 isCallerAuthorized() 函数前添加函数级注释,说明鉴权策略(同 UID 校验)和适用场景(会话总线)']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['为 isCallerAuthorized() 添加函数级注释,例如:/* 检查 DBus 调用者 UID 是否与当前进程 UID 一致,仅允许同用户调用 */']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: ['建议后续考虑将 encrypt_helper.cpp 中的 srand(time(nullptr)) 替换为密码学安全的随机数生成器(如 RAND_bytes),提升对称密钥的随机性强度(此为既有问题,非本次引入)']


💡 改进建议代码示例

// 建议为 isCallerAuthorized() 添加函数级注释:

/**
 * @brief 检查当前 DBus 调用者是否已授权
 *
 * 通过查询 DBus 守护进程获取调用者的 Unix UID,
 * 与当前进程 UID 进行比较。仅允许同 UID 的调用者执行操作。
 * 适用于会话总线(session bus)场景。
 *
 * @return true 表示调用者已授权或非方法调用消息;false 表示未授权
 */
bool DBusLockAgent::isCallerAuthorized()
{
    QDBusMessage msg = message();
    if (msg.type() != QDBusMessage::MethodCallMessage) {
        return true;
    }

    QString caller = msg.service();
    if (caller.isEmpty()) {
        return false;
    }

    QDBusInterface dbusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus",
                                "org.freedesktop.DBus", QDBusConnection::sessionBus());
    QDBusReply<quint32> reply = dbusInterface.call("GetConnectionUnixUser", caller);
    if (reply.isValid()) {
        quint32 callerUid = reply.value();
        if (callerUid != getuid()) {
            qCWarning(DDE_SHELL) << "Caller UID mismatch:" << callerUid << "vs" << getuid();
            return false;
        }
        return true;
    }

    qCWarning(DDE_SHELL) << "Failed to get caller UID:" << reply.error().message();
    return false;
}

本报告由 AI 代码审查工具自动生成

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.

1 participant