Skip to content

Commit a4018e9

Browse files
bdehamerCopilot
andcommitted
ci: address review feedback on dist rebuild workflows
- Grant pull-requests: read in rebuild-dist.yml, required by dependabot/fetch-metadata. - Harden commit-dist.yml: strictly validate head-ref/head-sha read from the PR-context artifact (40-hex sha, safe ref charset, single line) and require head-sha to exist before use, preventing workflow-command injection into $GITHUB_OUTPUT. Co-authored-by: Copilot App <[email protected]>
1 parent 7f0c113 commit a4018e9

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

.github/workflows/commit-dist.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,33 @@ jobs:
4040
path: incoming
4141

4242
# No artifact => the builder found dist/ already up to date. Nothing to do.
43+
# The head-ref/head-sha values come from an artifact produced in the
44+
# (unprivileged) PR context, so validate them strictly before writing to
45+
# $GITHUB_OUTPUT to avoid workflow-command injection.
4346
- name: Check for artifact
4447
id: check
4548
run: |
46-
if [ -d incoming/dist ] && [ -f incoming/dist-meta/head-ref ]; then
47-
echo "present=true" >> "$GITHUB_OUTPUT"
48-
echo "head-ref=$(cat incoming/dist-meta/head-ref)" >> "$GITHUB_OUTPUT"
49-
echo "head-sha=$(cat incoming/dist-meta/head-sha)" >> "$GITHUB_OUTPUT"
50-
else
49+
if [ ! -d incoming/dist ] || [ ! -f incoming/dist-meta/head-ref ] || [ ! -f incoming/dist-meta/head-sha ]; then
5150
echo "present=false" >> "$GITHUB_OUTPUT"
51+
exit 0
52+
fi
53+
54+
head_ref="$(head -n1 incoming/dist-meta/head-ref | tr -d '\r\n')"
55+
head_sha="$(head -n1 incoming/dist-meta/head-sha | tr -d '\r\n')"
56+
57+
if ! printf '%s' "$head_sha" | grep -Eq '^[0-9a-f]{40}$'; then
58+
echo "Invalid head-sha; refusing to proceed." >&2
59+
exit 1
60+
fi
61+
if ! printf '%s' "$head_ref" | grep -Eq '^[A-Za-z0-9._/-]+$'; then
62+
echo "Invalid head-ref; refusing to proceed." >&2
63+
exit 1
5264
fi
5365
66+
echo "present=true" >> "$GITHUB_OUTPUT"
67+
echo "head-ref=$head_ref" >> "$GITHUB_OUTPUT"
68+
echo "head-sha=$head_sha" >> "$GITHUB_OUTPUT"
69+
5470
- name: Checkout PR branch
5571
if: steps.check.outputs.present == 'true'
5672
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

.github/workflows/rebuild-dist.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212

1313
permissions:
1414
contents: read
15+
pull-requests: read # required by dependabot/fetch-metadata
1516

1617
jobs:
1718
rebuild:

0 commit comments

Comments
 (0)