GHSA-hw6r-g8gj-2987 Actions expression injection in `filter-test-configs` (`GHSL-2023-181`)

Not scored Published

Attackers can inject code via malicious branch names in PyTorch's filter-test-configs action, potentially leaking secrets and executing commands.

Exploited in the wild
Not known
Login needed
Any signed-in user
Attackable
Over the internet
Victim action needed
Not needed
Fix
None listed

What is GHSA-hw6r-g8gj-2987?

GHSA-hw6r-g8gj-2987 is a code injection vulnerability in https://github.com/pytorch/pytorch/.github/actions/filter-test-configs, published on 30 Aug 2023. Any signed-in user can exploit it over the network, with no action from the victim.

Official description

The pytorch/pytorch filter-test-configs workflow is vulnerable to an expression injection in Actions, allowing an attacker to potentially leak secrets and alter the repository using the workflow.

Details

The filter-test-configs workflow is using the raw github.event.workflow_run.head_branch value inside the filter step:

- name: Select all requested test configurations
  shell: bash
  env:
    GITHUB_TOKEN: ${{ inputs.github-token }}
    JOB_NAME: ${{ steps.get-job-name.outputs.job-name }}
  id: filter
  run: |
    ...
    python3 "${GITHUB_ACTION_PATH}/../../scripts/filter_test_configs.py" \
      ...
      --branch "${{ github.event.workflow_run.head_branch }}"

In the event of a repository using filter-test-configs in a pull_request_target-triggered workflow, an attacker could use a malicious branch name to gain command execution in the step and potentially leak secrets.

name: Example

on: pull_request_target

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - name: Filter
        uses: pytorch/pytorch/.github/actions/filter-test-configs@v2

Impact

This issue may lead to stealing workflow secrets.

Remediation

  1. Use an intermediate environment variable for potentially attacker-controlled values such as github.event.workflow_run.head_branch:
- name: Select all requested test configurations
  shell: bash
  env:
    GITHUB_TOKEN: ${{ inputs.github-token }}
    JOB_NAME: ${{ steps.get-job-name.outputs.job-name }}
    HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
  id: filter
  run: |
    ...
    python3 "${GITHUB_ACTION_PATH}/../../scripts/filter_test_configs.py" \
      ...
      --branch "$HEAD_BRANCH"

Resources

Which versions are affected by GHSA-hw6r-g8gj-2987?

1 open source package ship an affected version, including https://github.com/pytorch/pytorch/.github/actions/filter-test-configs.

PackageAffectedFixed in
https://github.com/pytorch/pytorch/.github/actions/filter-test-configs GitHub ActionsAll versionsNone

How do I fix GHSA-hw6r-g8gj-2987?

No fix has been published for GHSA-hw6r-g8gj-2987 yet. Limit exposure of the affected software until one is available.

Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.

Is GHSA-hw6r-g8gj-2987 being exploited?

There is no known exploitation of GHSA-hw6r-g8gj-2987 in the wild and no public exploit code.

Sources

Is GHSA-hw6r-g8gj-2987 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free