Skip to content

Arbitrary Expression Injection in github workflow leads to Command execution & leaking secrets

Critical
mehah published GHSA-q6gr-wc79-v589 Dec 30, 2023

Package

actions "Analysis - SonarCloud" workflow (GitHub Actions)

Affected versions

latest

Patched versions

None

Description

Summary

The /mehah/otclient "Analysis - SonarCloud" workflow is vulnerable to an expression injection in Actions, allowing an attacker to run commands remotely on the runner, leak secrets and alter the repository using this workflow.

Details

The otclient/.github/workflows/analysis-sonarcloud.yml file contains the vulnerable code

- name: Run PR sonar-scanner
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS }}" \
--define sonar.cfamily.cache.enabled=true \
--define sonar.cfamily.cache.path="$HOME/.cfamily" \
--define sonar.cfamily.compile-commands=build/compile_commands.json \
--define sonar.pullrequest.key=${{ github.event.pull_request.number }} \
--define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
--define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }}

      - name: Run PR sonar-scanner
        if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: |
          sonar-scanner \
            --define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS  }}" \
            --define sonar.cfamily.cache.enabled=true \
            --define sonar.cfamily.cache.path="$HOME/.cfamily" \
            --define sonar.cfamily.compile-commands=build/compile_commands.json \
            --define sonar.pullrequest.key=${{ github.event.pull_request.number }} \
            --define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
            --define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }}

The injection point would be the ${{ github.event.pull_request.head.ref }}.
The attack scenario was reproduced in a separate repository as follow:

  1. The attacker fork the repository
  2. Create a new branch with the payload sss$(whoami)]@sim4n6. Write a PR

Screenshot 2023-12-17 at 01-09-01 testsim4n6_teeest1

  1. Make a pull request to trigger the workflow and run the command sonar-scanner .... --define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}. Which is equivalent to sonar-scanner .... --define sss$(whoami)]@sim4n6.

As a result, the command was successfully injected into the runner, as seen in the alternative repository with a similar workflow raw logs:

Screenshot 2023-12-17 at 01-10-48 https __pipelinesghubeus15 actions githubusercontent com

Impact

  • Run arbitrary commands on the runner.
  • Leak the secrets & the tokens.

References

Severity

Critical

CVE ID

CVE-2024-21623

Weaknesses

Credits