Chore/ci#124
Conversation
| - name: Validate PR commits with commitlint | ||
| run: | | ||
| git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_branch | ||
| npx commitlint --from ${{ github.event.pull_request.base.sha }} --to pr_branch --verbose |
Check warning
Code scanning / CodeQL
Checkout of untrusted code in trusted context Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
To fix the problem, you should prevent the checkout and execution of untrusted PR code in a privileged context. The best practice is to separate the untrusted PR handling from privileged workflows. Specifically:
- Remove any direct fetching or checking out of PR HEAD code in a privileged workflow.
- Instead, perform commit linting in a workflow triggered by
pull_request(unprivileged) rather than viaworkflow_callorpull_request_target. - If you need to communicate results to privileged workflows, use artifacts and the
workflow_runpattern as described in the background. - For the workflow in question, you should remove the step that fetches and checks out the PR branch and instead run commitlint only on trusted code or in an unprivileged context.
Specifically, in .github/workflows/commitlint.yml, you should remove or adjust the step:
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_branch
and not run commitlint on untrusted PR code when triggered from a privileged context.
| @@ -41,7 +41,7 @@ | ||
| run: | | ||
| echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js | ||
|
|
||
| - name: Validate PR commits with commitlint | ||
| run: | | ||
| git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_branch | ||
| npx commitlint --from ${{ github.event.pull_request.base.sha }} --to pr_branch --verbose | ||
| # Removed unsafe checkout and validation of untrusted PR branch. | ||
| # To safely lint PR commits, run this workflow from a 'pull_request' trigger and only on trusted refs. | ||
| # If needed, use artifacts to communicate results to privileged workflows. | ||
| # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request for safe patterns. |
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup uv | ||
| uses: astral-sh/setup-uv@v5 |
Check warning
Code scanning / CodeQL
Unpinned tag for a non-immutable Action in workflow or composite action Medium
Development Package