Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/dev-lead-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,44 @@ jobs:
with:
token: ${{ secrets.GH_PAT_DON_PETRY_WRITER || secrets.GH_PAT_DON_PETRY || secrets.GH_PAT_WORKFLOWS || github.token }}

- name: Validate dev-lead ref input
id: agent-ref
shell: bash
env:
AGENT_REF: ${{ inputs.agent_ref }}
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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[High] The character-class check ^[A-Za-z0-9._/-]+$ (combined with only blocking ^refs/pull/ and 40-char hex SHAs) still allows untrusted refs: actions/checkout resolves shorthand PR refs (pull/<n>/head, pull/<n>/merge), abbreviated commit SHAs (7–39 hex chars), and arbitrary unmerged branch names, all of which match ^[A-Za-z0-9._/-]+$. In addition, writing $ref to $GITHUB_ENV on line 278 triggers a new CodeQL Environment variable built from user-controlled sources alert, and the second Checkout dev-lead scripts step in the downstream job remains unvalidated. Validate $ref against an explicit allowlist of valid dev-lead channel/release refs (^main$|^dev-lead/(v[0-9]+(\.[0-9]+\.[0-9]+|-(stable|next|ring[0-9]+))|stable|next|ring[0-9]+)$) and pass it via $GITHUB_OUTPUT (steps.<id>.outputs.ref) in both jobs.

echo "::error::inputs.agent_ref contains invalid characters: $ref"
exit 1
fi

echo "ref=$ref" >> "$GITHUB_OUTPUT"

- name: Checkout dev-lead scripts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: combsmith/.github-private
# Pinned channel (e.g. dev-lead/stable) when a trigger stub passes it;
# defaults to "main" → unchanged behaviour (#535/#506).
ref: ${{ inputs.agent_ref }}
ref: ${{ steps.agent-ref.outputs.ref }}
path: .dev-lead
# Cross-repo callers: github.token cannot read a private org repo — ensure
# GH_PAT_WORKFLOWS is set as an org or repo secret in the calling repo.
Expand Down
Loading