Skip to content

Lesson 6 of 9 · 28m

Supply-Chain and Injection Hardening for CI

The real attack surface: mutable actions, untrusted pull requests, script injection, cache poisoning, and token misuse.

CI is a remote code execution platform with credentials attached. That sentence should shape every hardening decision. Attackers do not need to break GitHub; they need your workflow to run their code, in your context, with your token. Most defenses are cheap. Most organizations skip them because the YAML still "works."

Pin third-party actions to immutable SHAs

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2

Tags can move. A compromised or renamed action tag can change what your pipeline runs tomorrow. Full commit SHAs are immutable. This is tedious, which is why Dependabot or Renovate should automate updates instead of humans avoiding them.

Prefer actions from trusted publishers, verify the repository behind the action, and read what permissions it requires. An action that uploads source to a third-party service is not "just a linter."

pull_request_target is the sharp end

pull_request runs in the context of the merge commit but with restricted token permissions and no secrets for forks. pull_request_target runs in the context of the base repository, often with secrets and write permissions. Untrusted input can meet privileged execution.

on:
  pull_request_target:
    types: [labeled]
permissions:
  pull-requests: write
  contents: read
jobs:
  labeler:
    if: github.event.label.name == 'safe-to-test'
    runs-on: ubuntu-latest
    steps:
      - run: gh pr edit "$PR_NUMBER" --add-label ci-queued
        env:
          GH_TOKEN: ${{ github.token }}
          PR_NUMBER: ${{ github.event.pull_request.number }}

Never check out the pull request head and execute its code in a pull_request_target job unless you have a deliberate gate, isolated environment, and no secrets. This is the canonical GitHub Actions footgun.

Script injection is still injection

Anything interpolated into run becomes shell code:

# dangerous: title text becomes shell source
run: echo "Title: ${{ github.event.pull_request.title }}"
# safer: pass data through environment
env:
  PR_TITLE: ${{ github.event.pull_request.title }}
run: printf '%s\n' "$PR_TITLE"

The first form can execute shell syntax embedded in a pull request title. The second passes data through the environment instead of splicing it into source. Safer does not mean immune; if you then eval or concatenate it into another command, you rebuilt the vulnerability.

Cache and artifacts are trust boundaries

Caches keyed only by branch can be poisoned by less-trusted refs and reused by more-trusted ones. Prefer scoped keys and do not cache sensitive build outputs. Artifacts uploaded from untrusted jobs should be treated as hostile input downstream. Validate file names, sizes, checksums, and formats before deploying them.

Field notes

  • Restrict which actions can run at the organization level; allowlisting by creator or verified action reduces noise.
  • Do not expose secrets to fork pull requests. The default protections exist because this attack is routine.
  • Use shell: bash explicitly and set -euo pipefail in scripts; silent partial failure is a security issue when later steps assume success.
  • Review workflow changes with the same care as authentication code. CI YAML is production security infrastructure.

Was this lesson helpful?

Sign in to rate