Detecting Supply Chain Attacks in CI/CD
When to Use
- When investigating security incidents that require detecting supply chain attacks in ci cd
- When building detection rules or threat hunting queries for this domain
- When SOC analysts need structured procedures for this analysis type
- When validating security monitoring coverage for related attack techniques
Detection Gaps & Validation
- SHA-pinning checks miss tag-pinning illusions: flagging
@main/@v3is right, but a@v3tag (or even a short SHA) is mutable/forgeable — only a full 40-char commit SHA is immutable. Also a pinned action can still pull unpinned transitive actions ordocker://image:latestinside itself; recurse into reusable workflows (uses: org/repo/.github/workflows/x.yml@ref) and DockerfileFROMlines. - Script-injection detection is broader than
github.event: untrusted input also flows throughgithub.head_ref,github.event.pull_request.title/body,github.event.issue.*, andenv:derived from them. Match the whole untrusted-context set inrun:blocks, not justgithub.event. pull_request_target+ checkout of PR head is the classic poisoned-pipeline RCE that YAML linting alone misses — flag workflows that combinepull_request_targetwithactions/checkoutof the PR ref and any secret access.- Dependency confusion isn't in the YAML: it lives in registry scope/
.npmrc/pip.confconfig — name-collision risk needs the package manifests, not just.github/workflows. - Validate the scan fires: add a deliberately vulnerable test workflow (unpinned
@main,run: echo ${{ github.event.issue.title }},permissions: write-all) and confirm each rule flags it. FP tuning: first-party/org-owned actions and internal reusable workflows are lower risk — allowlist trusted orgs rather than alerting on every@-ref.
Prerequisites
- Familiarity with security operations concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
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:
- Unpinned GitHub Actions (using @main instead of SHA)
- Script injection via ${{ github.event }} expressions
- Overly permissive GITHUB_TOKEN permissions
- Third-party actions with write access to repo
- 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]}")