Coordinated Disclosure Timeline

Summary

Insecure usage of pull_request_target makes docfx repository vulnerable to secrets exfiltration.

Project

dotnet/docfx

Tested Version

2.75.3

Details

Untrusted checkout leading to secrets exfiltration from a Pull Request in CI workflow (GHSL-2024-030)

The pull_request_target trigger event used in ci.yml GitHub workflow explicitly checks out the head of the Pull Request and therefore code controlled by an attacker and runs it.

name: ci
on:
  pull_request_target:
    branches: [ main, feature/*, hotfix/* ]
  push:
    branches: [ main, feature/*, hotfix/* ]

jobs:
  test:
    runs-on: ${{ matrix.os }}
    environment: ci
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, macos-latest, ubuntu-latest]
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{github.event.pull_request.head.ref}}
        repository: ${{ github.event.pull_request.head.repo.full_name }}
        lfs: true

    - uses: ./.github/actions/build

    - run: npm run lint
      shell: bash
      working-directory: templates
...

    - run: percy exec -- dotnet test -c Release -f net8.0 --filter Stage=Percy --no-build --collect:"XPlat Code Coverage"
      if: matrix.os == 'ubuntu-latest'
      env:
        PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
...

By explicitly checking out and running a code from a fork, the untrusted code is running in an environment that is able to access secrets. See Preventing pwn requests for more information.

An attacker could create a pull request with a malicious templates/packages.json file which would execute arbitrary commands in the runner gaining access to the secrets shared with the workflow (eg: secrets.PERCY_TOKEN).

This vulnerability was found using the Checkout of untrusted code in trusted context CodeQL query.

Proof Of Concept (PoC)

To verify the vulnerability follow the following steps:

```

Impact

Running untrusted code with a privileged repository token and access to secrets may lead to an unauthorized repository modification or exfiltration of the secrets. Please note that this allows for exfiltration of the secrets.PERCY_TOKEN.

Credit

This issue was discovered and reported by GHSL team member @pwntester (Alvaro Muñoz).

Contact

You can contact the GHSL team at securitylab@github.com, please include a reference to GHSL-2024-030 in any communication regarding this issue.