Skip to content

Commit 9151ac2

Browse files
fix: github workflow vulnerable to script injection (#2663)
* inline repo's full_name as env var Signed-off-by: Diogo Teles Sant'Anna <[email protected]> Co-authored-by: Diego Marquez <[email protected]>
1 parent a7e4fd6 commit 9151ac2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

.github/workflows/hermetic_library_generation.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ on:
1919
paths:
2020
- 'generation_config.yaml'
2121

22+
23+
env:
24+
HEAD_REF: ${{ github.head_ref }}
25+
REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
26+
GITHUB_REPOSITORY: ${{ github.repository }}
27+
2228
jobs:
2329
library_generation:
24-
# skip pull requests coming from a forked repository
25-
if: github.event.pull_request.head.repo.full_name == github.repository
2630
runs-on: ubuntu-latest
2731
steps:
2832
- uses: actions/checkout@v4
@@ -32,11 +36,15 @@ jobs:
3236
- name: Generate changed libraries
3337
shell: bash
3438
run: |
35-
set -x
39+
set -ex
40+
if [[ "${GITHUB_REPOSITORY}" != "${REPO_FULL_NAME}" ]]; then
41+
echo "This PR comes from a fork. Generation will be skipped"
42+
exit 0
43+
fi
3644
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
3745
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
3846
bash .github/scripts/hermetic_library_generation.sh \
3947
--target_branch ${{ github.base_ref }} \
40-
--current_branch ${{ github.head_ref }}
48+
--current_branch $HEAD_REF
4149
env:
4250
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

0 commit comments

Comments
 (0)