Skip to content

fix: security issues CWE-78 and CWE-290 in sessionmanager - #244

Open
fly602 wants to merge 1 commit into
masterfrom
agent/agent/6e487a86e304
Open

fly602 wants to merge 1 commit into
masterfrom
agent/agent/6e487a86e304

Conversation

@fly602

@fly602 fly602 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

安全修复

CWE-78: OS命令注入 (sessionmanager.cpp:633)

  • 问题: 使用 执行 autostop 脚本,存在 shell 注入风险
  • 修复: 改为直接执行脚本文件,跳过非可执行文件

CWE-290: 认证绕过 (sessionmanager.cpp:492)

  • 问题: 使用 文本前缀作为调用者身份验证依据,cmdline 可被伪造
  • 修复: 改用 符号链接验证调用者可执行文件路径,避免 cmdline 伪造

Summary by Sourcery

Harden session manager caller validation and autostop script execution against command injection and authentication bypass vulnerabilities.

Bug Fixes:

  • Prevent command injection when launching autostop scripts by executing only executable files directly.
  • Prevent caller authentication bypass by validating the requesting process executable path instead of spoofable command-line contents.

Influence:
- CWE-78: execute autostop scripts directly instead of bash -c to avoid shell injection
- CWE-290: use /proc/<PID>/exe symlink instead of cmdline text for caller verification
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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 (collapsed on small PRs)

Reviewer's Guide

Hardens sessionmanager by authenticating SetLocked callers through /proc executable identity rather than spoofable cmdline contents, and by directly executing only executable autostop files without a shell.

Sequence diagram for secure SetLocked caller authentication

sequenceDiagram
    participant Caller
    participant SessionManager
    participant ProcFS as /proc/PID/exe

    Caller->>SessionManager: SetLocked(lock)
    SessionManager->>ProcFS: symLinkTarget(/proc/PID/exe)
    ProcFS-->>SessionManager: executable path
    alt path is /usr/bin/dde-lock or /usr/libexec/deepin/dde-lock
        SessionManager->>SessionManager: apply lock state
    else path is not authorized
        SessionManager-->>Caller: reject request
    end
Loading

File-Level Changes

Change Details Files
Replaced spoofable command-line caller validation with executable-path validation via /proc//exe.
  • Resolve the D-Bus caller PID.
  • Read the /proc executable symlink and allow only the two approved dde-lock paths.
  • Log and reject callers whose executable path is missing or unauthorized.
src/dde-session/impl/sessionmanager.cpp
Removed shell-mediated autostop script execution to prevent OS command injection.
  • Skip files without executable permissions.
  • Execute executable scripts directly with an empty argument list instead of invoking /bin/bash -c.
  • Warn when a script is skipped.
src/dde-session/impl/sessionmanager.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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 CWE-78(命令注入)和 CWE-290(认证绕过)两个安全问题,修复方案正确且无新增漏洞。SetLocked 函数改用 /proc/PID/exe 符号链接替代可伪造的 /proc/PID/cmdline 验证调用者身份,launchAutostopScripts 函数改为直接执行可执行文件并检查可执行权限,替代了原先通过 bash -c 执行任意脚本的方式。四维度均通过,代码质量良好。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: ['可在 QFile::symLinkTarget 返回空字符串时增加专门检查并输出不同级别的日志,例如 qWarning() << "SetLocked: failed to resolve caller exe for pid:" << pid; 以区分解析失败与非法调用者']


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['建议确认 EXEC_COMMAND 宏内部实现是否使用 execvp 直接执行而非通过 shell,以确保彻底消除命令注入风险']


💡 改进建议代码示例

// SetLocked 函数建议增加空路径检查以提升可调试性:
void SessionManager::SetLocked(bool lock)
{
    uint pid = connection().interface()->servicePid(message().service()).value();

    // 使用 /proc/<PID>/exe 符号链接验证调用者可执行文件路径,避免 cmdline 伪造
    QString exePath = QFile::symLinkTarget(QString("/proc/%1/exe").arg(pid));
    if (exePath.isEmpty()) {
        qWarning() << "SetLocked: failed to resolve caller exe for pid:" << pid;
        return;
    }
    if (exePath != "/usr/bin/dde-lock" && exePath != "/usr/libexec/deepin/dde-lock") {
        qWarning() << "SetLocked: illegal caller exe:" << exePath;
        return;
    }

    // ... 后续逻辑
}

本报告由 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.

2 participants