Skip to content

Potential fix for code scanning alert no. 266: Checkout of untrusted code in trusted context - #58

Merged
joel-rieke merged 1 commit into
mainfrom
alert-autofix-266
Jan 28, 2026
Merged

Potential fix for code scanning alert no. 266: Checkout of untrusted code in trusted context#58
joel-rieke merged 1 commit into
mainfrom
alert-autofix-266

Conversation

@joel-rieke

Copy link
Copy Markdown
Collaborator

Potential fix for https://github.com/trimble-oss/go-mysql-server/security/code-scanning/266

In general, to fix this type of issue you should avoid explicitly checking out the pull request head commit in a privileged or semi‑privileged workflow, and instead rely on the default behavior of actions/checkout for pull_request events (which checks out the merge commit) or restructure into separate unprivileged and privileged workflows as described in the background. This prevents unreviewed PR code from being executed with elevated repository access.

For this specific workflow, the minimal, behavior‑preserving fix is to stop forcing actions/checkout to use ref: ${{ github.head_ref }} in the verify job. When on: pull_request is used, omitting the ref causes actions/checkout@v3 to check out the merge commit of the PR into the base branch in a safe, read‑only context. The verify job only needs to see the combined changes to run ./check_repo.sh; it does not need to execute the PR’s own version of that script from the head ref. Therefore:

  • In .github/workflows/format.yml, within the verify job, remove the with: block that sets ref: ${{ github.head_ref }} on the actions/checkout@v3 step (lines 61–62).
  • Leave the rest of the workflow unchanged; format and alt-verify behavior remain the same.
  • No new imports or actions are needed.

This change ensures that the verify job runs against the safe merge ref and no longer explicitly pulls and executes potentially untrusted PR‑head scripts in a way that triggers the CodeQL warning.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…code in trusted context

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@joel-rieke
joel-rieke marked this pull request as ready for review January 28, 2026 18:40
@joel-rieke
joel-rieke merged commit cb12ca9 into main Jan 28, 2026
9 of 12 checks passed
@joel-rieke
joel-rieke deleted the alert-autofix-266 branch January 28, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants