What is script injection, and how do you fix it?
AdvancedConceptOIDC & Security Hardening
Answer
Interpolating attacker-controlled context into run: lets them inject shell commands, because ${{ }} is substituted into the script text.
# Vulnerable
- run: echo "Title: ${{ github.event.pull_request.title }}"
# Fixed
- env:
TITLE: ${{ github.event.pull_request.title }}
run: echo "Title: $TITLE"
Untrusted fields include PR and issue titles and bodies, comment bodies, branch names (head_ref), commit messages, author names and emails, and labels. The same applies to actions/github-script script: blocks. Linters like actionlint and zizmor flag these patterns.
More on OIDC & Security Hardening
How does GitHub OIDC work, end to end?IntermediateWhat are the `sub` claim formats, and which do you put in an AWS trust policy?AdvancedConfigure OIDC to AWS: provider, role and workflow.AdvancedConfigure OIDC to Azure.AdvancedConfigure OIDC to GCP.AdvancedWhy pin actions to a full commit SHA, and how do you keep pins updated?Intermediate