Skip to content

【安全】修复 autostop 脚本 CWE-78 命令注入漏洞 - #241

Draft
mhduiy wants to merge 1 commit into
masterfrom
agent/developer/9ac893fed7de
Draft

mhduiy wants to merge 1 commit into
masterfrom
agent/developer/9ac893fed7de

Conversation

@mhduiy

@mhduiy mhduiy commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

修复内容

修复 SessionManager::launchAutostopScripts() 中的 CWE-78 命令注入漏洞。

修改内容

  • 消除命令注入向量:将 bash -c <path> 改为 bash <path>,文件路径作为脚本文件参数而非 shell 命令字符串传递
  • 跳过符号链接:通过 info.isSymLink() 检测并跳过符号链接,防止指向非预期文件
  • 属主校验:用户级目录文件属主须为当前用户(getuid()),系统级目录文件属主须为 root(uid 0)
  • 权限校验:不允许 group/other 可写(S_IWGRP | S_IWOTH),防止其他用户篡改脚本内容
  • 使用 lstat() 代替 stat():校验作用于链接本身,消除 TOCTOU 窗口
  • 缓存 QStandardPaths 调用:提取到循环外,避免重复调用

影响范围

  • 仅修改 launchAutostopScripts() 方法体及新增 #include <sys/stat.h>
  • 不改动方法签名、调用方、其他功能
  • autostop 脚本仍以 bash 执行,正常脚本行为不受影响

关联 Issue

DDE-517

Summary by Sourcery

Harden autostop script execution against command injection and unsafe script files.

Bug Fixes:

  • Prevent command injection when launching autostop scripts by executing validated script paths directly with Bash.
  • Reject symlinked, incorrectly owned, or group/world-writable autostop scripts before execution.

Enhancements:

  • Cache the user configuration path while discovering autostop scripts.

将 bash -c <path> 改为 bash <path>,消除命令注入向量;
增加属主/权限校验(lstat、符号链接跳过、group/other 可写检查)。

Log: 修复安全漏洞 CWE-78
@mhduiy
mhduiy marked this pull request as draft October 30, 2026 04:47
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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 Oct 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

本 PR 在不改变 autostop 调用接口和 Bash 执行行为的前提下,通过将路径作为脚本参数传递、跳过符号链接并校验文件属主与写权限,降低命令注入及脚本篡改风险,同时缓存配置路径以避免重复查询。

Sequence diagram for secure autostop script launch

sequenceDiagram
    participant SessionManager
    participant FileSystem
    participant Bash

    SessionManager->>FileSystem: entryInfoList()
    loop each autostop file
        alt info.isSymLink()
            SessionManager-->>SessionManager: [skip symlink]
        else regular file
            SessionManager->>FileSystem: lstat()
            alt unsafe owner or permissions
                SessionManager-->>SessionManager: [skip unsafe file]
            else trusted file
                SessionManager->>Bash: EXEC_COMMAND(/bin/bash, absoluteFilePath)
                Bash-->>SessionManager: execute script file
            end
        end
    end
Loading

File-Level Changes

Change Details Files
将 autostop 脚本从 shell 命令字符串执行改为脚本文件参数执行,并增加文件安全校验。
  • 使用 /bin/bash <script> 替代 bash -c <path>,消除路径被解释为命令字符串的注入入口。
  • 跳过符号链接,并通过 lstat() 校验链接本身。
  • 要求用户目录脚本属主为当前用户、系统目录脚本属主为 root,且禁止 group/other 可写文件。
src/dde-session/impl/sessionmanager.cpp
优化脚本目录路径处理。
  • 缓存用户配置目录路径,复用于目录拼接和属主判断。
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 ✨

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