Skip to content

ci: bind the branch name to env before writing it to GITHUB_ENV - #6251

Open
kobihikri wants to merge 1 commit into
jina-ai:masterfrom
kobihikri:ci/branch-name-via-env
Open

ci: bind the branch name to env before writing it to GITHUB_ENV#6251
kobihikri wants to merge 1 commit into
jina-ai:masterfrom
kobihikri:ci/branch-name-via-env

Conversation

@kobihikri

Copy link
Copy Markdown

Hi, and thanks for Jina.

In .github/workflows/label-pr.yml, the deploy-to-netlify job writes the branch name into the environment file by interpolation:

- run: |
    echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV

Actions expands ${{ ... }} into the script text before bash runs, so the branch name becomes part of the command. Git allows $, (, ) and backticks in branch names, and $(...) executes inside double quotes — so a PR from a fork on a branch named x$(id) would run that rather than have its name recorded.

There is a second, quieter effect worth mentioning: because this writes to $GITHUB_ENV, a value containing a newline can define additional environment variables for every later step in the job, not just BRANCH_NAME. The very next step consumes it as ref: ${{ env.BRANCH_NAME }} for a checkout of jina-ai/jina.

The change binds the value to a step-level environment variable first:

- env:
    HEAD_REF: ${{ github.head_ref }}
  run: |
    echo "BRANCH_NAME=$HEAD_REF" >> $GITHUB_ENV

BRANCH_NAME still ends up with the same value and the checkout below is unchanged.

On scope: this is a pull_request trigger, so a fork PR carries a read-only token and no secrets. Hardening rather than a live exploit.

Disclosure: I used AI assistance to help spot this and prepare the change, and I read the job and the step that consumes BRANCH_NAME myself.

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