Skip to content

fix(ci): add CodeQL workflow for fork pull requests#74

Merged
bug-ops merged 3 commits intomainfrom
fix/codeql-fork-pr
Mar 19, 2026
Merged

fix(ci): add CodeQL workflow for fork pull requests#74
bug-ops merged 3 commits intomainfrom
fix/codeql-fork-pr

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 19, 2026

Problem

CodeQL analysis did not run for PR #72 because it is a fork pull request (wtfbbqhax/mcplsbug-ops/mcpls).

Root cause: The repository uses GitHub's CodeQL "default setup" (configured via repository settings), which only runs on PRs from the same repository. The pull_request event from a fork does not grant write access to security-events, so GitHub's default setup silently skips fork PRs.

Evidence:

Fix

Add an explicit codeql.yml workflow using pull_request_target trigger. This event runs in the context of the base repository (with access to security-events: write) while checking out the PR head SHA for analysis.

The workflow covers:

  • push to main (replacing default setup for push events)
  • pull_request_target for all PRs including forks
  • Weekly scheduled scan

Security Note

pull_request_target with actions/checkout ref: pr.head.sha checks out untrusted fork code. This is safe for CodeQL because:

  • No secrets are used in the analysis
  • Permissions are locked to security-events: write and contents: read only
  • The workflow does not build and execute the code with elevated privileges

Note on Default Setup

GitHub's default CodeQL setup remains active and will also run on push/schedule. Consider disabling it in repository Settings → Code security → Code scanning to avoid duplicate analyses on non-fork PRs.

GitHub's default CodeQL setup only runs on PRs from the same repository.
Fork PRs (like #72) are skipped because pull_request events from forks
don't have write access to the base repo's security events.

Add an explicit codeql.yml workflow using pull_request_target so CodeQL
analysis runs for both fork and non-fork PRs. The workflow checks out
the PR head SHA explicitly while keeping permissions minimal
(security-events: write, contents: read only).
@github-actions github-actions bot added the ci/cd CI/CD pipeline changes label Mar 19, 2026
bug-ops added 2 commits March 20, 2026 00:22
Checking out fork head SHA in a pull_request_target context grants
untrusted code access to the privileged workflow environment.
Remove the explicit ref override so checkout defaults to the base
branch, which is the correct and secure behavior for CodeQL analysis.

Fixes CodeQL alert: Checkout of untrusted code in trusted context
Restore ref: pull_request.head.sha for pull_request_target so CodeQL
scans the actual fork PR changes instead of the base branch.

This pattern is safe because the job has no access to secrets and only
holds security-events: write + contents: read permissions. Added inline
comment to suppress the CodeQL false-positive alert and document the
security reasoning.
@bug-ops bug-ops enabled auto-merge (squash) March 19, 2026 23:34
@bug-ops bug-ops disabled auto-merge March 19, 2026 23:34
@bug-ops bug-ops merged commit 122780f into main Mar 19, 2026
14 checks passed
@bug-ops bug-ops deleted the fix/codeql-fork-pr branch March 19, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD pipeline changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant