Skip to content

Commit 79bc1ad

Browse files
fix(ci): Prevent command injection in ci-metadata workflow
Move GitHub context interpolation into an environment variable to prevent potential command injection attacks. The github.event.pull_request.head.sha and other GitHub context data can contain arbitrary user input and should not be directly interpolated into shell scripts. References: - Parent ticket: https://linear.app/getsentry/issue/VULN-1328 - Child ticket: https://linear.app/getsentry/issue/JS-1972 - https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#understanding-the-risk-of-script-injections Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c167cf2 commit 79bc1ad

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

.github/workflows/ci-metadata.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ jobs:
5151
id: get_metadata
5252
# We need to try a number of different options for finding the head commit, because each kind of trigger event
5353
# stores it in a different location
54+
env:
55+
COMMIT_SHA_EXPR: ${{ github.event.pull_request.head.sha || github.event.head_commit.id || inputs.head_commit }}
5456
run: |
55-
COMMIT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha || github.event.head_commit.id || inputs.head_commit }})
57+
COMMIT_SHA=$(git rev-parse --short "$COMMIT_SHA_EXPR")
5658
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
5759
echo "COMMIT_MESSAGE=$(git log -n 1 --pretty=format:%s $COMMIT_SHA)" >> $GITHUB_ENV
5860

0 commit comments

Comments
 (0)