Skip to content

Avoid script injection when setting Percy branch from refs#729

Open
arpitjain099 wants to merge 1 commit into
coinbase:masterfrom
arpitjain099:chore/harden-expression-injection
Open

Avoid script injection when setting Percy branch from refs#729
arpitjain099 wants to merge 1 commit into
coinbase:masterfrom
arpitjain099:chore/harden-expression-injection

Conversation

@arpitjain099
Copy link
Copy Markdown

The Percy-branch steps in visreg-mobile.yml and visreg-web.yml set PERCY_BRANCH by writing ${{ github.head_ref }} (and ${{ github.ref_name }}) directly into a run: script:

echo "PERCY_BRANCH=${{ github.head_ref }}" >> "$GITHUB_ENV"

GitHub Actions substitutes ${{ }} expressions into the script text before the shell runs, so the branch name a contributor chooses becomes part of the command. A pull request branch named with shell metacharacters could run arbitrary commands in the job. The mobile workflow also folds ${{ inputs.branch }} into the same script, which has the same issue.

The fix is the one recommended in GitHub's script-injection hardening guidance: bind the untrusted values to step env: entries and read them as ordinary shell variables. Static analyzers such as CodeQL (actions/expression-injection) and zizmor report the original form for the same reason.

I kept the branch-selection logic identical; only the reference style changed. Given the repo already pins actions by SHA and runs harden-runner, this felt in line with the existing posture.

Both visual-regression workflows build PERCY_BRANCH by interpolating
github.head_ref and github.ref_name directly into a run block. The
runner expands these expressions into the script before bash sees it,
so a pull request opened from a branch with a crafted name could inject
commands into the step.

Move the branch values into a step env block and reference them as
shell variables. The Percy branch resolution is identical; only the
substitution point changes from the script text to the environment.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@cb-heimdall
Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 1
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1
CODEOWNERS 🟡 See below

🟡 CODEOWNERS

Code Owner Status Calculation
ui-systems-eng-team 🟡 0/1
Denominator calculation
Additional CODEOWNERS Requirement
Show calculation
Sum 0
0
From CODEOWNERS 1
Sum 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants