Skip to content

fix(ci): prevent PR title shell injection - #35

Merged
dhicoc merged 1 commit into
zhaoxuya520:mainfrom
doublecurry:codex/pr1-ci-shell-injection
Aug 3, 2026
Merged

fix(ci): prevent PR title shell injection#35
dhicoc merged 1 commit into
zhaoxuya520:mainfrom
doublecurry:codex/pr1-ci-shell-injection

Conversation

@doublecurry

@doublecurry doublecurry commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

说明

针对 auto-merge-journal.yml 中直接嵌入 PR 变量导致的 Shell 命令注入隐患进行修复,并将动态输入统一调整为环境变量传递;同步新增 CI 安全性的自动化测试脚本。

改动

  • 工作流安全重构 (.github/workflows/auto-merge-journal.yml)

    • 将原本内联使用的 ${{ github.event.pull_request.number }}${{ github.event.pull_request.title }} 统一提取至 Job 级别的 env 环境变量(PR_NUMBER, PR_TITLE, PR_SUBJECT)。
    • 在执行 gh pr diffgh pr mergegh pr comment 时,将内联表达式替换为双引号包裹的环境变量(如 "$PR_NUMBER""$PR_SUBJECT"),阻断命令注入路径。
  • 安全回归测试 (skills/scripts/test-workflow-title-safety.ps1)

    • 新增 PowerShell 校验脚本,通过正则严格检查工作流文件中是否存在将 github.event 直接拼接进 Shell 指令的行为。
    • 针对带有引号、换行符及拼接命令的恶意标题(Metacharacters)进行模拟校验,确保元字符不会被 Shell 意外解释或执行。

@dhicoc
dhicoc merged commit 62ba932 into zhaoxuya520:main Aug 3, 2026
gh pr merge "$PR_NUMBER" \
--auto --squash \
--subject "[field-journal] ${{ github.event.pull_request.title }}"
--subject "$PR_SUBJECT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

111+ --subject "$SR SUBJE"

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