Open1

Impostor Commits の検出方法

Shunsuke SuzukiShunsuke Suzuki

https://www.chainguard.dev/unchained/what-the-fork-imposter-commits-in-github-actions-and-ci-cd

Impostor Commit は GitHub の Fork Network を悪用し、 Fork したリポジトリに悪意のあるコミットを生成してあたかも元のリポジトリの安全なコミットであるかのように見せかける攻撃手法。

あるコミットが Impostor Commit かどうかを識別する GitHub API は存在しない。
しかし、 zizmor には Impostor Commit を検出する機能があるのでどうやって実現しているか調べた。

https://docs.zizmor.sh/audits/#impostor-commit

zizmor は clank という別の OSS のロジックを参考にしているらしい。
幸いこちらは Go で実装されているので読みやすい。

https://github.com/chainguard-dev/clank

コードを読んだところ以下のようなロジックなようだ。

https://github.com/chainguard-dev/clank/blob/17b76a6c3392df6fa72c80936fe510ee9192d6a2/main.go#L244-L288

  1. 元のリポジトリの全 branch, tag を取得する
  2. branch (の HEAD), tag と指定した SHA を compare two commits API で比較
  3. branch 内のコミットなら compare できてかつ diff の status が behind か identical になるはず。これを満たす branch か tag が見つからなければ impostor commit

ここで検出された commit は必ずしも fork の commit とは限らない。
というのも、 PR をマージして feature branch を削除したら、 feature branch のコミットは上のロジックでは impostor commit になる。
恐らく原理上このようなコミットが元のリポジトリに属しているか fork で生成されたものなのか判別する方法はない。