Skip to content

Commit 24737e0

Browse files
olivermeyerclaude
andauthored
chore(security): prevent script and commit-message injections (#512)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3b736f8 commit 24737e0

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

.github/actions/run-tests/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ runs:
3030
(!contains(inputs.commit-message, 'skip:test:all')) &&
3131
(!contains(github.event.pull_request.labels.*.name, 'skip:test:all'))
3232
shell: bash
33+
env:
34+
MAKE_TARGET: ${{ inputs.make-target }}
35+
SUMMARY_TITLE: ${{ inputs.summary-title }}
3336
run: |
3437
set +e
35-
make ${{ inputs.make-target }}
38+
make $MAKE_TARGET
3639
EXIT_CODE=$?
3740
# Show test execution in GitHub Job summary
3841
found_files=0
@@ -44,7 +47,7 @@ runs:
4447
fi
4548
done
4649
if [ $found_files -eq 0 ]; then
47-
echo "# ${{ inputs.summary-title }}" >> $GITHUB_STEP_SUMMARY
50+
echo "# $SUMMARY_TITLE" >> $GITHUB_STEP_SUMMARY
4851
echo "" >> $GITHUB_STEP_SUMMARY
4952
fi
5053
# Show test coverage in GitHub Job summary

.github/workflows/_package-publish.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ jobs:
167167

168168
- name: Print the release notes
169169
shell: bash
170-
run: cat "${{ steps.git-cliff.outputs.changelog }}"
170+
env:
171+
GIT_CLIFF_CHANGELOG: ${{ steps.git-cliff.outputs.changelog }}
172+
run: cat "$GIT_CLIFF_CHANGELOG"
171173

172174
- name: Build distribution into dist/
173175
shell: bash
@@ -202,23 +204,27 @@ jobs:
202204
(!contains(github.event.pull_request.labels.*.name, 'skip:test:all'))
203205
env:
204206
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
207+
GH_REF_NAME: ${{ github.ref_name }}
208+
GIT_CLIFF_CHANGELOG: ${{ steps.git-cliff.outputs.changelog }}
205209
shell: bash
206210
run: |
207211
rm -rf ./test-results/coverage_html
208-
gh release create ${{ github.ref_name }} ./dist/* ./dist_native_zipped/* ./test-results/* ./audit-results/* \
209-
--notes-file ${{ steps.git-cliff.outputs.changelog }}
212+
gh release create "$GH_REF_NAME" ./dist/* ./dist_native_zipped/* ./test-results/* ./audit-results/* \
213+
--notes-file "$GIT_CLIFF_CHANGELOG"
210214
211215
- name: Create GitHub release (no test results)
212216
if: |
213217
(contains(inputs.commit_message, 'skip:test:all')) ||
214218
(contains(github.event.pull_request.labels.*.name, 'skip:test:all'))
215219
env:
216220
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
221+
GH_REF_NAME: ${{ github.ref_name }}
222+
GIT_CLIFF_CHANGELOG: ${{ steps.git-cliff.outputs.changelog }}
217223
shell: bash
218224
run: |
219225
rm -rf ./test-results/coverage_html
220-
gh release create ${{ github.ref_name }} ./dist/* ./dist_native_zipped/* ./audit-results/* \
221-
--notes-file ${{ steps.git-cliff.outputs.changelog }}
226+
gh release create "$GH_REF_NAME" ./dist/* ./dist_native_zipped/* ./audit-results/* \
227+
--notes-file "$GIT_CLIFF_CHANGELOG"
222228
223229
- name: Inform Sentry about release
224230
uses: getsentry/action-release@dab6548b3c03c4717878099e43782cf5be654289 # v3.5.0
@@ -233,10 +239,12 @@ jobs:
233239
- name: Convert release notes from Markdown to Slack mrkdwn
234240
id: slack-notes
235241
shell: bash
242+
env:
243+
GIT_CLIFF_CONTENT: ${{ steps.git-cliff.outputs.content }}
236244
run: |
237245
# Convert Markdown links [text](url) to Slack mrkdwn <url|text>
238246
# Convert bold **text** to *text*
239-
SLACK_RELEASE_NOTES=$(echo '${{ toJSON(steps.git-cliff.outputs.content) }}' | \
247+
SLACK_RELEASE_NOTES=$(printf '%s\n' "$GIT_CLIFF_CONTENT" | \
240248
sed -E 's/\[([^]]+)\]\(([^)]+)\)/<\2|\1>/g' | \
241249
sed -E 's/\*\*([^*]+)\*\*/*\1*/g')
242250
echo "content<<SLACKEOF" >> "$GITHUB_OUTPUT"

.github/workflows/build-native-only.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ jobs:
3030
- name: Get commit message
3131
id: get-commit-message
3232
shell: bash
33+
env:
34+
GITHUB_EVENT_NAME: ${{ github.event_name }}
35+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
36+
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
3337
run: |
34-
if [ "${{ github.event_name }}" == "pull_request" ]; then
38+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
3539
# For PR events, get the commit message from the PR head SHA
36-
COMMIT_MESSAGE=$(git log -1 --format=%B ${{ github.event.pull_request.head.sha }})
40+
COMMIT_MESSAGE=$(git log -1 --format=%B "$PR_HEAD_SHA")
3741
else
3842
# For push events, use the head commit message
39-
COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
43+
COMMIT_MESSAGE="$HEAD_COMMIT_MESSAGE"
4044
fi
4145
# Export for use in other steps (multiline-safe)
4246
# Use printf with %s to avoid interpreting special characters
@@ -56,9 +60,12 @@ jobs:
5660
steps:
5761
- name: Check if workflow should run
5862
id: check
63+
env:
64+
COMMIT_HAS_MARKER: ${{ contains(needs.get-commit-message.outputs.commit_message, 'build:native:only') }}
65+
PR_HAS_MARKER: ${{ contains(github.event.pull_request.labels.*.name, 'build:native:only') }}
5966
run: |
60-
if [[ "${{ contains(needs.get-commit-message.outputs.commit_message, 'build:native:only') }}" == "true" ]] || \
61-
[[ "${{ contains(github.event.pull_request.labels.*.name, 'build:native:only') }}" == "true" ]]; then
67+
if [[ "$COMMIT_HAS_MARKER" == "true" ]] || \
68+
[[ "$PR_HAS_MARKER" == "true" ]]; then
6269
echo "should_run=true" >> $GITHUB_OUTPUT
6370
echo "✅ Workflow triggered: Found 'build:native:only' in commit message or PR labels"
6471
else

.github/workflows/ci-cd.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ jobs:
4343
- name: Get commit message
4444
id: get-commit-message
4545
shell: bash
46+
env:
47+
GITHUB_EVENT_NAME: ${{ github.event_name }}
48+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
49+
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
4650
run: |
47-
if [ "${{ github.event_name }}" == "pull_request" ]; then
51+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
4852
# For PR events, get the commit message from the PR head SHA
49-
COMMIT_MESSAGE=$(git log -1 --format=%B ${{ github.event.pull_request.head.sha }})
53+
COMMIT_MESSAGE=$(git log -1 --format=%B $PR_HEAD_SHA)
5054
else
5155
# For push events, use the head commit message
52-
COMMIT_MESSAGE='${{ github.event.head_commit.message }}'
56+
COMMIT_MESSAGE="$HEAD_COMMIT_MESSAGE"
5357
fi
5458
# Export for use in other steps (multiline-safe)
5559
# Use printf with %s to avoid interpreting special characters

0 commit comments

Comments
 (0)