Skip to content

Actions: Fix Critical Artifact poisoning False Positive #19388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

AdnaneKhan
Copy link

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

@Copilot Copilot AI review requested due to automatic review settings April 25, 2025 19:16
@AdnaneKhan AdnaneKhan requested a review from a team as a code owner April 25, 2025 19:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll: Language not supported

@github-actions github-actions bot added the Actions Analysis of GitHub Actions label Apr 25, 2025
@JarLob
Copy link
Contributor

JarLob commented Jul 8, 2025

Hi, I was pinged about it by Simon.

@AdnaneKhan you need to add a change note, see https://github.com/github/codeql/pull/19085/files#diff-a654ec6cec8af7e22ef1dc59ec11f5095d05128d97d67cdb2cbfe98e0fec6210 for an example.
Also a test is needed in actions/ql/test/query-tests/Security/CWE-829.

@tausbn @asgerf, can we have a review to have tests run? I wonder if it breaks anything. It looks fishy to me that the original tmp check was added in the first place as sanitizer as if it prevents code execution from the untrusted artifact if it was downloaded to tmp.

Copy link
Contributor

@JarLob JarLob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above.

AdnaneKhan and others added 2 commits July 8, 2025 10:17
Co-authored-by: Jaroslav Lobačevski <jarlob@github.com>
@AdnaneKhan
Copy link
Author

Hi, I was pinged about it by Simon.

@AdnaneKhan you need to add a change note, see https://github.com/github/codeql/pull/19085/files#diff-a654ec6cec8af7e22ef1dc59ec11f5095d05128d97d67cdb2cbfe98e0fec6210 for an example. Also a test is needed in actions/ql/test/query-tests/Security/CWE-829.

@tausbn @asgerf, can we have a review to have tests run? I wonder if it breaks anything. It looks fishy to me that the original tmp check was added in the first place as sanitizer as if it prevents code execution from the untrusted artifact if it was downloaded to tmp.

Thanks - I added a change note and a test workflow file but I'm not sure how to specify the test - is the ArtifactPoisoningCritical.expected file an assertion on the state of the codeql graph?

@JarLob
Copy link
Contributor

JarLob commented Jul 8, 2025

The file is automatically generated by codeql test command. Usually I just right click on the test folder, run test, see if the changes make sense and then accept them.

The fix was a little more involving, I have created the tests, but cannot push to your branch. Do you have the check allow collaboration? Or maybe it is because I not CodeQL maintainer?..

@JarLob
Copy link
Contributor

JarLob commented Jul 8, 2025

Alternatively you may pull from https://github.com/JarLob/codeql/tree/pr/AdnaneKhan/19388-1

@AdnaneKhan
Copy link
Author

Alternatively you may pull from https://github.com/JarLob/codeql/tree/pr/AdnaneKhan/19388-1

Merged your changes in!

@owen-mc
Copy link
Contributor

owen-mc commented Jul 10, 2025

The CI check doesn't like the change-note filename. Which is odd, because it seems to match one of the options that it gives. Anyway, try changing it to 2025-07-08-critical-artififact-poisoning.md

@owen-mc
Copy link
Contributor

owen-mc commented Jul 10, 2025

I've made https://github.com/github/semmle-code/pull/53513 to fix the change note file name CI check acting differently than it says it does.

Copy link
Contributor

@Napalys Napalys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that looks good to me.
Could you please change the change note filename to something like 2025-07-08-artifact-poisoning.md so it would pass the current CI? Otherwise, we'll need to wait for the @owen-mc's fix to be merged.

@AdnaneKhan
Copy link
Author

Thank you, that looks good to me. Could you please change the change note filename to something like 2025-07-08-artifact-poisoning.md so it would pass the current CI? Otherwise, we'll need to wait for the @owen-mc's fix to be merged.

Updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions Analysis of GitHub Actions documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants