Skip to content

security: ci: read the branch name from the environment - #22

Open
Shengcun-Scanner wants to merge 1 commit into
promptfoo:mainfrom
Shengcun-Scanner:shengcun/cicd-shell-injection-head-ref
Open

Shengcun-Scanner wants to merge 1 commit into
promptfoo:mainfrom
Shengcun-Scanner:shengcun/cicd-shell-injection-head-ref

Conversation

@Shengcun-Scanner

Copy link
Copy Markdown

The maintenance-scope check echoes the head branch inside its bash script:

- name: Validate maintenance PR scope
  run: |
    …
    echo "Branch ${{ github.head_ref }} is not a generated release branch; …"

The expression is expanded before bash parses the script, so a pull request from
a branch named

$(id)

runs that command while the job validates the PR. The job runs on pull_request
with permissions: contents: read, so the blast radius is that job's token and
whatever the step itself can reach — worth closing, not a privileged runner.

Fix

- name: Validate maintenance PR scope
  if: ${{ !startsWith(github.head_ref, 'release/code-scan-action-v') }}
  env:
    HEAD_REF: ${{ github.head_ref }}
  run: |
    …
    echo "Branch $HEAD_REF is not a generated release branch; …"

The other github.head_ref uses in this file are inside if: expressions and an
existing env: block, where the value is data — untouched.

Verification

$ P='$(touch /tmp/pwned)'
$ bash -c 'echo "Branch '"$P"' is not a release"'      # before
$ ls /tmp/pwned                                        # -> exists
$ HOOK="$P" bash -c 'echo "Branch $HOOK is not a release"'   # after
$ ls /tmp/pwned                                        # -> not found

yaml.safe_load still parses the workflow.

The maintenance-scope step echoed the head branch straight into its script, so a
branch name containing a command substitution ran in the validation job. Read it
from env instead.

Co-Authored-By: Shengcun <business@rs-systems-web.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T14:31:06.621355Z 16a240c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant