Potential fix for code scanning alert no. 16: Checkout of untrusted code in trusted context#17
Conversation
There was a problem hiding this comment.
Pull request overview
This PR attempts to address a code-scanning alert ("Checkout of untrusted code in trusted context") by switching release-please-bump-lockfile.yml from a direct pull_request trigger to a workflow_run trigger that fires when the "Release Please" workflow completes, and replaces the head_ref/author gating with a check that the upstream run was a successful pull_request event.
Changes:
- Replace
on: pull_requestwithon: workflow_runfor the "Release Please" workflow. - Replace the
startsWith(github.head_ref, 'release-please--')+ bot-author gate withworkflow_run.event == 'pull_request' && conclusion == 'success'. - Leave the rest of the job (checkout via
github.head_ref,cargo check, push back to PR branch) unchanged.
Comments suppressed due to low confidence (1)
.github/workflows/release-please-bump-lockfile.yml:38
- In a
workflow_run-triggered job,github.head_refis not populated (it is only set forpull_request/pull_request_targetevents). Both the checkoutref: ${{ github.head_ref }}on line 44 and thegit push origin "HEAD:${{ github.head_ref }}"on line 85 will therefore resolve to an empty string and fail (or checkout the wrong branch). Usegithub.event.workflow_run.head_branch(andgithub.event.workflow_run.head_repository.full_name) instead, and note that for apush-triggered upstream workflow this will bemain, not a PR branch — meaning the strategy of amending into the release-please PR branch doesn't translate to aworkflow_runon a push-driven workflow.
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| startsWith(github.head_ref, 'release-please--') && | ||
| github.event.pull_request.user.login == 'github-actions[bot]' | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' |
There was a problem hiding this comment.
Fixed in c7b9c9c. The security gates are now restored properly:
-
Correct event type: The
ifguard now checksgithub.event.workflow_run.event == 'push'(release-please.yml triggers on push to main, never pull_request) and addsname == 'Release Please'as extra defense-in-depth. -
Branch-name + author gates restored: A new
find-prstep queriesgh pr list --author "github-actions[bot]" --limit 1and filters with.headRefName | startswith("release-please--"). Only when a matching open bot-authored PR is found does the checkout andcargo checkproceed — all subsequent steps gate onsteps.find-pr.outputs.branch != ''. -
github.head_reffixed: That variable is empty in aworkflow_runcontext. All checkout and push steps now use${{ steps.find-pr.outputs.branch }}instead. -
pull-requests: readadded to allowgh pr listto run. -
Comment block updated to accurately describe the new API-based validation flow.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe workflow is restructured from a pull_request trigger to a workflow_run companion that fires after Release Please completes. It now discovers the active Release Please PR branch via GitHub CLI, checks out that branch, regenerates the Cargo.lock file, and pushes updates directly to the discovered branch instead of the GitHub context head_ref. ChangesRelease Please Lockfile Automation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Comment |
c7b9c9c to
51e2e65
Compare
…ode in trusted context Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ockfile.yml Agent-Logs-Url: https://github.com/InstaZDLL/WaveFlow/sessions/d0f26cf9-cd35-4e46-85d7-3bda258b89dd Co-authored-by: InstaZDLL <72951793+InstaZDLL@users.noreply.github.com>
51e2e65 to
04d5ace
Compare
Potential fix for https://github.com/InstaZDLL/WaveFlow/security/code-scanning/16
General fix: do not run checkout/build of PR HEAD in a job that has write permissions. Use an unprivileged PR workflow to compute/validate outputs, then a separate privileged
workflow_runworkflow to apply trusted updates after validation.Best fix for this file, without changing the intended behavior too much: convert this workflow from direct
pull_requestexecution toworkflow_runso this file is no longer the “untrusted checkout in trusted context” workflow. In this file, remove direct PR checkout/build execution trigger and gate execution on completion of a dedicated unprivileged workflow. (That unprivileged workflow should generate/verify what is needed; this file should only do privileged write actions after strict checks.)Within the shown file region, the concrete safe change is:
on: pull_requestblock withon: workflow_run(completed).ifgate validatingworkflow_run.event == 'pull_request'and successful conclusion.contents: writeonly if still required for final push).Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Summary by CodeRabbit