Skip to content

chore: update cppcheck.yml workflow configuration - #351

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:agent/developer/efeef32897da
Oct 21, 2026
Merged

BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:agent/developer/efeef32897da

Conversation

@BLumia

@BLumia BLumia commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Changes

  1. Upgrade actions/checkout from v3 to v7
  2. Add allow-unsafe-pr-checkout: true parameter for PR checkout

This update ensures the cppcheck workflow uses the latest checkout action version and supports unsafe PR checkout as needed.


Multica Issue: DDE-476

Summary by Sourcery

Modernize the cppcheck workflow checkout configuration for pull-request validation.

Enhancements:

  • Update the cppcheck workflow to use the latest checkout action and support required pull-request checkout behavior.

CI:

  • Update the cppcheck GitHub Actions workflow configuration.

1. Upgrade actions/checkout from v3 to v7
2. Add allow-unsafe-pr-checkout: true parameter for PR checkout
3. Keep existing cppcheck workflow structure unchanged

Influence:
1. Verify cppcheck workflow triggers on pull requests
2. Confirm checkout action v7 works correctly with unsafe PR checkout

chore: 更新 cppcheck.yml 工作流配置

1. 将 actions/checkout 从 v3 升级至 v7
2. 新增 allow-unsafe-pr-checkout: true 参数用于 PR checkout
3. 保持现有 cppcheck 工作流结构不变

Influence:
1. 验证 cppcheck 工作流在 PR 上正常触发
2. 确认 checkout action v7 在 unsafe PR checkout 模式下正常工作
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The cppcheck GitHub Actions workflow now uses actions/checkout v7 and explicitly permits unsafe pull-request checkout while continuing to analyze the pull request head commit without persisting credentials.

Sequence diagram for cppcheck pull request checkout

sequenceDiagram
    participant GitHubActions
    participant Checkout as actions/checkout@v7
    participant Cppcheck as linuxdeepin/action-cppcheck@main
    GitHubActions->>Checkout: checkout(ref, persist-credentials, allow-unsafe-pr-checkout)
    Checkout-->>GitHubActions: pull request head commit
    GitHubActions->>Cppcheck: run github_token analysis
    Cppcheck-->>GitHubActions: cppcheck results
Loading

File-Level Changes

Change Details Files
Update the cppcheck workflow's repository checkout configuration for newer action compatibility and PR head checkout behavior.
  • Upgrade the checkout action from v3 to v7.
  • Enable unsafe pull-request checkout explicitly while retaining the PR head SHA and disabled credential persistence.
  • Leave the cppcheck execution step and token wiring unchanged.
.github/workflows/cppcheck.yml

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

@BLumia
BLumia marked this pull request as ready for review October 21, 2026 08:57

@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=".github/workflows/cppcheck.yml" line_range="21" />
<code_context>
         with:
           ref: ${{ github.event.pull_request.head.sha }}
           persist-credentials: false
+          allow-unsafe-pr-checkout: true
       - uses: linuxdeepin/action-cppcheck@main
         with:
</code_context>
<issue_to_address>
**Untrusted PR code enters privileged job**

When an attacker-controlled PR head is checked out and its content reaches an unsafe execution or interpretation path in the scanner, a malicious PR can supply the checked-out workspace to `linuxdeepin/action-cppcheck@main`, which also receives `GITHUB_TOKEN`; if crafted input is executed or interpreted unsafely by the analysis step, the token is exposed or abused. The caller sees a compromised token-bearing workflow run.

Avoid checking out untrusted PR code in a `pull_request_target` job that receives a token; run analysis in an unprivileged `pull_request` workflow or isolate it and restrict token permissions.
</issue_to_address>

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

with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
allow-unsafe-pr-checkout: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical · Untrusted PR code enters privileged job

When an attacker-controlled PR head is checked out and its content reaches an unsafe execution or interpretation path in the scanner, a malicious PR can supply the checked-out workspace to linuxdeepin/action-cppcheck@main, which also receives GITHUB_TOKEN; if crafted input is executed or interpreted unsafely by the analysis step, the token is exposed or abused. The caller sees a compromised token-bearing workflow run.

Avoid checking out untrusted PR code in a pull_request_target job that receives a token; run analysis in an unprivileged pull_request workflow or isolate it and restrict token permissions.

Prompt for AI agents
In `.github/workflows/cppcheck.yml` at line 21:

**Untrusted PR code enters privileged job**

When an attacker-controlled PR head is checked out and its content reaches an unsafe execution or interpretation path in the scanner, a malicious PR can supply the checked-out workspace to `linuxdeepin/action-cppcheck@main`, which also receives `GITHUB_TOKEN`; if crafted input is executed or interpreted unsafely by the analysis step, the token is exposed or abused. The caller sees a compromised token-bearing workflow run.

Avoid checking out untrusted PR code in a `pull_request_target` job that receives a token; run analysis in an unprivileged `pull_request` workflow or isolate it and restrict token permissions.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Fail


📊 总体评价

项目 结果
审查结论 代码审查未通过
评分详情 本次提交升级 actions/checkout 至 v7 并添加 allow-unsafe-pr-checkout: true 参数, 在 pull_request_target 触发的工作流中显式启用了不安全的 PR 代码检出行为。 该工作流向后续 action 传递 secrets.GITHUB_TOKEN(具有仓库写权限), 若 cppcheck action 执行或处理 PR 中的不可信代码(如 Makefile、CMakeLists.txt), 恶意 PR 可窃取 GITHUB_TOKEN 或篡改仓库。v7 默认会阻止此不安全行为, 但该 flag 主动重新启用了它,构成新增高危漏洞。建议将触发器改为 pull_request 或添加最小权限声明。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔓

评价: 存在1个安全漏洞 ❌ 不通过

🔐 发现 1 个安全漏洞

安全漏洞详情:

  1. 🟡 权限绕过 (.github/workflows/cppcheck.yml - cppcheck workflow): allow-unsafe-pr-checkout: true 在 pull_request_target 触发的工作流中显式启用不安全的 PR 代码检出。该工作流以基础仓库的 GITHUB_TOKEN(写权限)运行,并将 secrets.GITHUB_TOKEN 传递给 linuxdeepin/action-cppcheck@main。若该 action 执行 PR 中的不可信代码,恶意 PR 可窃取 GITHUB_TOKEN 并篡改仓库。actions/checkout@v7 默认阻止此不安全行为,该 flag 主动绕过保护——非常重要

建议: ['将工作流触发器从 pull_request_target 改为 pull_request,使工作流以 PR 自身的有限权限运行, 而非基础仓库的密钥。若需要写权限发布审查评论,可使用单独的 pull_request_target 作业仅发布评论。', '若必须保留 pull_request_target,添加最小权限的 permissions 块: permissions: { contents: read, pull-requests: write }', '将 linuxdeepin/action-cppcheck@main 固定到特定 commit SHA,避免 @main 分支被篡改时引入恶意代码。', '移除第 16 行 - run: export(预存问题),该命令将所有环境变量输出到日志,可能泄露敏感信息。']


💡 改进建议代码示例

# 方案1(推荐):将触发器改为 pull_request,移除 allow-unsafe-pr-checkout
name: cppcheck
on:
  pull_request:
    paths-ignore:
      - ".github/workflows/**"

permissions:
  contents: read
  pull-requests: write

jobs:
  cppchceck:
    name: cppcheck
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - uses: linuxdeepin/action-cppcheck@<full-commit-sha>  # 固定到特定 SHA
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          repository: ${{ github.repository }}
          pull_request_id: ${{ github.event.pull_request.number }}
          allow_approve: false

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, Ivy233

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

@BLumia
BLumia merged commit 1a3fb25 into linuxdeepin:master Oct 21, 2026
10 checks passed
@BLumia
BLumia deleted the agent/developer/efeef32897da branch October 21, 2026 09:16
@BLumia

BLumia commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

备注:allow-unsafe-pr-checkout: true 是必须提供的参数,不然此 CI 无法正常工作。

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