codeql icon indicating copy to clipboard operation
codeql copied to clipboard

Actions: Fix Critical Artifact poisoning False Positive

Open AdnaneKhan opened this issue 6 months ago • 0 comments
trafficstars

The artifact poisoning CodeQL query creates a Critical false-positive under the following scenario:

I believe this PR will fix it because it unless the path extraction functionality in CodeQL resolves/sanitizes the context values in some way.

Below is an example that reproduces the false positive:

name: Test False Positive
on:
  workflow_run:
    workflows:
      - Benchmark
    types:
      - completed

permissions:
  contents: read

jobs:
  benchmark:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Download From PR
        uses: actions/download-artifact@v4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          run-id: ${{ github.event.workflow_run.id }}
          path: ${{ runner.temp }}/artifacts/
      - run: npm install

This is particularly a problem because the examples for a secure workflow specifically calls out this fix.

name: Secure Workflow

on:
  workflow_run:
    workflows: ["Prev"]
    types:
      - completed

jobs:
  Download:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: mkdir -p ${{ runner.temp }}/artifacts/
      - uses: dawidd6/action-download-artifact@v2
        with:
          name: pr_number
          path: ${{ runner.temp }}/artifacts/

      - name: Run command
        run: |
          sh cmd.sh

AdnaneKhan avatar Apr 25 '25 19:04 AdnaneKhan