Skip to content

Commit 36a70e1

Browse files
authored
Fix pr preview vulnerability (emilk#5461)
* Closes emilk#5458 * [x] I have followed the instructions in the PR template
1 parent 4362a24 commit 36a70e1

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.github/workflows/preview_build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ jobs:
4242
- name: Generate meta.json
4343
env:
4444
PR_NUMBER: ${{ github.event.number }}
45-
PR_BRANCH: ${{ github.head_ref }}
45+
URL_SLUG: ${{ github.event.number }}-${{ github.head_ref }}
4646
run: |
47-
echo "{\"pr_number\": \"$PR_NUMBER\", \"pr_branch\": \"$PR_BRANCH\"}" > meta.json
47+
# Sanitize the URL_SLUG to only contain alphanumeric characters and dashes
48+
URL_SLUG=$(echo $URL_SLUG | tr -cd '[:alnum:]-')
49+
echo "{\"pr_number\": \"$PR_NUMBER\", \"url_slug\": \"$URL_SLUG\"}" > meta.json
4850
4951
- uses: actions/upload-artifact@v4
5052
with:

.github/workflows/preview_cleanup.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ jobs:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
1717
- run: mkdir -p empty_dir
18-
- name: Url slug variable
18+
- name: Generate URL_SLUG
19+
env:
20+
PR_NUMBER: ${{ github.event.pull_request.number }}
21+
URL_SLUG: ${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.ref }}
1922
run: |
20-
echo "URL_SLUG=${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
23+
# Sanitize the URL_SLUG to only contain alphanumeric characters and dashes
24+
URL_SLUG=$(echo $URL_SLUG | tr -cd '[:alnum:]-')
25+
echo "URL_SLUG=$URL_SLUG" >> $GITHUB_ENV
2126
- name: Deploy
2227
uses: JamesIves/github-pages-deploy-action@v4
2328
with:

.github/workflows/preview_deploy.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ jobs:
4040
- name: Parse meta.json
4141
run: |
4242
echo "PR_NUMBER=$(jq -r .pr_number meta.json)" >> $GITHUB_ENV
43-
echo "PR_BRANCH=$(jq -r .pr_branch meta.json)" >> $GITHUB_ENV
44-
45-
- name: Url slug variable
46-
run: |
47-
echo "URL_SLUG=${{ env.PR_NUMBER }}-${{ env.PR_BRANCH }}" >> $GITHUB_ENV
43+
echo "URL_SLUG=$(jq -r .url_slug meta.json)" >> $GITHUB_ENV
4844
4945
- name: Deploy
5046
uses: JamesIves/github-pages-deploy-action@v4

0 commit comments

Comments
 (0)