Skip to content

Potential fix for code scanning alert no. 40: Checkout of untrusted code in a non-privileged context - #2319

Draft
don-petry wants to merge 2 commits into
mainfrom
alert-autofix-40
Draft

don-petry wants to merge 2 commits into
mainfrom
alert-autofix-40

Conversation

@don-petry

@don-petry don-petry commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Potential fix for https://github.com/petry-projects/.github-private/security/code-scanning/40

Best fix: validate and constrain inputs.agent_ref before checkout, and fail closed on unsafe values. This keeps existing functionality (still allows intended pinned channels/branches/tags) while preventing PR refs/SHAs/paths that could be attacker-controlled in untrusted contexts.

In .github/workflows/dev-lead-reusable.yml, add a new step immediately before “Checkout dev-lead scripts” that:

  • Normalizes inputs.agent_ref with fallback to main.
  • Rejects dangerous patterns such as refs/pull/*, raw 40-hex SHAs, traversal characters, whitespace, or other non-safe characters.
  • Exports a validated ref (for example SAFE_AGENT_REF) into $GITHUB_ENV.

Then change the checkout step’s ref from ${{ inputs.agent_ref }} to ${{ env.SAFE_AGENT_REF }}.

No new dependencies are needed; shell validation is sufficient.

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

View guided diff Turn on auto-fix

Problem

See the linked issue.

Risk

Medium — changes GitHub Actions workflow behavior, which is exercised only post-merge; verify via the affected workflow runs.

Test plan

No test files were added or updated. Verification: bash scripts/dev-lead-lint.sh (shellcheck --severity=warning) ran pre-commit; the existing CI (bats + lint) guards the change.

Rollback

Revert this PR. No non-revertible side effects (no tags, migrations, or external state).

Monitoring

Watch the affected workflow run(s) in the Actions tab and this PR's Lint check for regressions.

…ode in a non-privileged context

Copilot Autofix

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@gemini-code-assist

This comment has been minimized.

@coderabbitai

This comment has been minimized.

Comment thread .github/workflows/dev-lead-reusable.yml Fixed
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (applied)

Changes committed and pushed. Requested items addressed:

  • .github/workflows/dev-lead-reusable.yml:253 — applied

Comment on lines +254 to +278
run: |
ref="$AGENT_REF"
if [ -z "$ref" ]; then
ref="main"
fi

# Block untrusted PR refs and unsafe ref formats.
if [[ "$ref" =~ ^refs/pull/ ]]; then
echo "::error::inputs.agent_ref must not be a pull-request ref: $ref"
exit 1
fi
if [[ "$ref" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "::error::inputs.agent_ref must not be a raw commit SHA: $ref"
exit 1
fi
if [[ "$ref" == *".."* || "$ref" == *":"* || "$ref" =~ [[:space:]] ]]; then
echo "::error::inputs.agent_ref contains unsafe characters: $ref"
exit 1
fi
if [[ ! "$ref" =~ ^[A-Za-z0-9._/-]+$ ]]; then
echo "::error::inputs.agent_ref contains invalid characters: $ref"
exit 1
fi

echo "SAFE_AGENT_REF=$ref" >> "$GITHUB_ENV"
@sonarqubecloud

Copy link
Copy Markdown

@donpetry-bot

donpetry-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

No description provided.

@donpetry-bot

donpetry-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

No description provided.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Operational notice acknowledged: CodeRabbit is informing us that automatic review was skipped because the PR is in draft status. This is not a code defect — it is an optional configuration matter. No changes to the PR itself are needed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Agent reasoning
Issues addressed: 0
- Draft PR notice: Operational notice — no code changes needed [replied with informational disposition]
Files changed: none
Skipped (informational): 1
```
The CodeRabbit comment is a **non-actionable operational notice** explaining that automatic review was skipped because the PR is in draft status. It contains no code defects, security findings, or architectural issues to address — only an optional configuration suggestion. Dispositioned with `informational` marker to clear the maintainer-comment gate.

@don-petry

Copy link
Copy Markdown
Collaborator Author

No description provided.

@don-petry

Copy link
Copy Markdown
Collaborator Author

This is an operational notice — the bot is unable to generate a review due to unsupported file types. All CI checks pass; there are no code issues to address.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Agent reasoning
---
## Summary
**Bot:** gemini-code-assist[bot]
**Issues addressed:** 0 (non-actionable notice)
**Dispositioning:**
- Bot notice: "unable to generate a review due to unsupported file types" → dispositioned as `informational` [replied with comment-disposition marker]
**Files changed:** None
**CI state:** All checks passing ✓ (no failures, no Tier 1 blockers)
The bot's comment is purely operational—it cannot review these file types, not that there are code defects. No code changes were needed. The original comment has been dispositioned with `informational` marker to clear the maintainer-comment gate.

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.

3 participants