技能 编程开发 CI/CD 供应链攻击检测

CI/CD 供应链攻击检测

v20260317
detecting-supply-chain-attacks-in-ci-cd
自动解析 GitHub Actions 与 CI/CD 流水线,识别未固定版本的 actions、表达式注入、依赖混淆和密钥权限过宽等供应链风险,帮助安全团队加固或调查受损构建系统。
获取技能
368 次下载
概览

Detecting Supply Chain Attacks in CI/CD

Instructions

Scan CI/CD workflow files for supply chain risks by parsing GitHub Actions YAML, checking for unpinned dependencies, script injection vectors, and secrets exposure.

import yaml
from pathlib import Path

for wf in Path(".github/workflows").glob("*.yml"):
    with open(wf) as f:
        workflow = yaml.safe_load(f)
    for job_name, job in workflow.get("jobs", {}).items():
        for step in job.get("steps", []):
            uses = step.get("uses", "")
            if uses and "@" in uses and not uses.split("@")[1].startswith("sha"):
                print(f"Unpinned action: {uses} in {wf.name}")

Key supply chain risks:

  1. Unpinned GitHub Actions (using @main instead of SHA)
  2. Script injection via ${{ github.event }} expressions
  3. Overly permissive GITHUB_TOKEN permissions
  4. Third-party actions with write access to repo
  5. Dependency confusion via public/private package name collision

Examples

# Check for script injection in run steps
for step in job.get("steps", []):
    run_cmd = step.get("run", "")
    if "${{" in run_cmd and "github.event" in run_cmd:
        print(f"Script injection risk: {run_cmd[:80]}")
信息
Category 编程开发
Name detecting-supply-chain-attacks-in-ci-cd
版本 v20260317
大小 8.43KB
更新时间 2026-03-18
语言