Skip to content

Commit c7fe3e4

Browse files
committed
Pass event values through the environment, never into the script
Both run blocks interpolated ${{ }} straight into the shell, which is the pattern GitHub's script injection guidance warns about: the expression is expanded before the shell sees it, so the value becomes part of the command rather than an argument to it. The two values here are a SHA and a number, so there is nothing to inject today, but the shape is the finding FIX_SHA and PR_NUMBER now arrive as environment variables and the scripts quote them, matching what the rest of the repository does Raised by AppSec against the backport-stack/ci branch, V2265233159
1 parent f9d2a7e commit c7fe3e4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

.github/workflows/backport-bot.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ jobs:
5959
- name: Install the AI client
6060
run: pip3 install --user anthropic boto3
6161
- name: Work out which branches need the fix
62+
# The SHA goes through the environment rather than into the script, so nothing
63+
# from the event is expanded by the shell. GitHub's script injection guidance:
64+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks
65+
env:
66+
FIX_SHA: ${{ github.event.pull_request.merge_commit_sha }}
6267
run: |
63-
util/backport/backport analyze \
64-
--commit "${{ github.event.pull_request.merge_commit_sha }}" --skip
68+
util/backport/backport analyze --commit "$FIX_SHA" --skip
6569
- name: Keep the verdict for the publish job
6670
uses: actions/upload-artifact@v4
6771
with:
@@ -92,8 +96,11 @@ jobs:
9296
name: backport-run
9397
path: util/backport/.backport-runs
9498
- name: Cherry-pick and open the pull requests
99+
# PR_NUMBER through the environment, not inlined into the script, same as in
100+
# analyze above
95101
env:
96102
GH_TOKEN: ${{ github.token }}
103+
PR_NUMBER: ${{ github.event.pull_request.number }}
97104
run: |
98105
# cherry-pick needs an author, and a runner has no git identity
99106
git config user.name "aws-lc-backport-bot"
@@ -102,5 +109,4 @@ jobs:
102109
# so the backport branches have nowhere else to go
103110
util/backport/backport apply --yes
104111
util/backport/backport publish \
105-
--pr "${{ github.event.pull_request.number }}" \
106-
--push-to-aws-lc --yes
112+
--pr "$PR_NUMBER" --push-to-aws-lc --yes

0 commit comments

Comments
 (0)