Skip to content

Commit aba8708

Browse files
authored
security: Harden GitHub Actions workflows (#2556)
* security: harden GitHub Actions workflows against credential exposure and fork PR attacks * gh default token for more steps * more gh default token * fix: for all external repos super token is needed * chore: use new GITHUB_TOKEN_MISTICA token with specific permissions * final naming * security: prevent script code injection
1 parent 2a13897 commit aba8708

14 files changed

Lines changed: 140 additions & 41 deletions

.github/workflows/ChatGPT-Reviewer.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ permissions:
66

77
on:
88
pull_request:
9+
types: [opened, edited]
10+
branches:
11+
- production
12+
- pre-production
913

1014
concurrency:
1115
group: ${{ github.repository }}-${{ github.event.number || github.head_ref || github.sha }}-${{ github.workflow }}
@@ -18,7 +22,7 @@ jobs:
1822
steps:
1923
- uses: platisd/openai-pr-description@master
2024
with:
21-
github_token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
2226
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
2327
sample_prompt: |
2428
You are a design system designer and your function is create a table with all the changes for a GitHub Pull Request in Markdown format.

.github/workflows/archived/stale-issues.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: "Close stale issues and PR"
22

3+
permissions:
4+
issues: write
5+
pull-requests: write
6+
37
on:
48
schedule:
59
- cron: "30 1 * * 1"

.github/workflows/changelog-index.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ on:
1414
jobs:
1515
changelog-index:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
1719
steps:
18-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v6
1921
with:
20-
token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
22+
persist-credentials: false
2123

2224
- name: Get branch name
2325
uses: rlespinasse/github-slug-action@v3.x
@@ -33,4 +35,4 @@ jobs:
3335
git config user.name "github-actions"
3436
git config user.email "github-actions[bot]@users.noreply.github.com"
3537
git commit -am "update changelog"
36-
git push origin ${{ env.GITHUB_REF_SLUG_URL }}
38+
git push https://x-access-token:${{ secrets.GH_TOKEN_MISTICA }}@github.com/${{ github.repository }}.git ${{ env.GITHUB_REF_SLUG_URL }}

.github/workflows/changelog.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,32 @@ on:
1818
jobs:
1919
release-notes:
2020
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
env:
24+
RELEASE_VERSION: ${{ github.event.inputs.releaseVersion }}
2125
steps:
22-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v6
2327
with:
24-
token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
28+
persist-credentials: false
29+
30+
- name: Validate release version format
31+
run: |
32+
if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
33+
echo "Invalid version format. Expected: X.Y.Z or X.Y.Z-suffix"
34+
exit 1
35+
fi
2536
2637
- name: Get branch name
2738
uses: rlespinasse/github-slug-action@v3.x
2839

2940
- name: Create Release Notes
3041
uses: docker://decathlon/release-notes-generator-action:3.1.5
3142
env:
32-
GITHUB_TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS }}
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3344
OUTPUT_FOLDER: changelog-versions
3445
USE_MILESTONE_TITLE: "true"
35-
FILENAME_PREFIX: ${{ github.event.inputs.releaseVersion }}
46+
FILENAME_PREFIX: ${{ env.RELEASE_VERSION }}
3647

3748
# - run: sudo python3 .github/resources/changelog-index-generator.py changelog-versions
3849

@@ -42,7 +53,7 @@ jobs:
4253
git config user.name "github-actions"
4354
git config user.email "github-actions[bot]@users.noreply.github.com"
4455
git commit -am "update changelog"
45-
git push origin ${{ env.GITHUB_REF_SLUG_URL }}
56+
git push https://x-access-token:${{ secrets.GH_TOKEN_MISTICA }}@github.com/${{ github.repository }}.git ${{ env.GITHUB_REF_SLUG_URL }}
4657
4758
# - name: Upload Release Notes to Wiki
4859
# uses: docker://decathlon/wiki-page-creator-action:latest

.github/workflows/link-checker.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ name: Link checker
33
on:
44
workflow_dispatch:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
link-checker:
811
runs-on: ubuntu-latest
912
steps:
10-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v6
14+
with:
15+
persist-credentials: false
1116

1217
- name: Link Checker
1318
id: lychee
1419
uses: lycheeverse/lychee-action@v1.5.1
1520
env:
16-
GITHUB_TOKEN: ${{secrets.NOVUM_PRIVATE_REPOS_READONLY}}
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/link-issue-project.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ name: Add Issues to Project
33
on:
44
issues:
55
types: [opened]
6+
7+
permissions:
8+
contents: read
9+
issues: read
10+
611
env:
7-
GITHUB_API_TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS_READONLY}}
12+
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
813

914
jobs:
1015
add_to_project:

.github/workflows/mistica-ai.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Mística AI Discussions
22

33
permissions:
44
contents: read
5-
pull-requests: write
5+
discussions: write
66

77
on:
88
discussion:
@@ -18,7 +18,7 @@ jobs:
1818
steps:
1919
- uses: platisd/openai-pr-description@master
2020
with:
21-
github_token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
21+
github_token: ${{ secrets.GITHUB_TOKEN }}
2222
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
2323
sample_prompt: |
2424
It acts as the person who will decide whether a design requirement should enter into an overall design system and complies with the following rules:
@@ -36,7 +36,7 @@ jobs:
3636
- name: Add comment to discussion
3737
run: |
3838
curl -X POST \
39-
-H "Authorization: Bearer ${{ secrets.NOVUM_PRIVATE_REPOS }}" \
39+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
4040
-H "Accept: application/vnd.github.v3+json" \
4141
https://api.github.com/repos/{owner}/{repo}/discussions/{discussion_number}/comments \
4242
--data-raw '{"body": "Generated response: ${description}"}'

.github/workflows/open-branches.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ on:
55
schedule:
66
- cron: 0 8 * * *
77

8+
permissions:
9+
contents: read
10+
issues: write
11+
812
jobs:
913
sync-figma-brand:
1014
runs-on: ubuntu-latest
11-
1215
steps:
1316
- name: Checkout repository
14-
uses: actions/checkout@v4
17+
uses: actions/checkout@v6
18+
with:
19+
persist-credentials: false
1520

1621
- name: Set up Python
1722
uses: actions/setup-python@v2
@@ -28,6 +33,6 @@ jobs:
2833
- name: Run sync for the brand(s)
2934
env:
3035
FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
31-
GITHUB_TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3237
working-directory: .github/issue-scripts
3338
run: python3 branch-table.py

.github/workflows/pending-tasks.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ on:
55
schedule:
66
- cron: 0 8 * * *
77

8+
permissions:
9+
contents: read
10+
issues: write
11+
812
jobs:
913
pending-tasks:
1014
runs-on: ubuntu-latest
1115
steps:
1216
- name: Checkout del repositorio
13-
uses: actions/checkout@v2
17+
uses: actions/checkout@v6
18+
with:
19+
persist-credentials: false
1420

1521
- name: Configurar Python
1622
uses: actions/setup-python@v2
@@ -24,6 +30,6 @@ jobs:
2430
2531
- name: Ejecutar script de búsqueda y actualizar issue
2632
env:
27-
TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS }}
33+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
2834
working-directory: .github/issue-scripts
2935
run: python3 pending-tasks.py

.github/workflows/schema-validator.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- pre-production
1111
- production
1212

13+
permissions:
14+
contents: read
15+
1316
jobs:
1417
validate-skins:
1518
runs-on: ubuntu-latest
@@ -32,6 +35,8 @@ jobs:
3235
steps:
3336
- name: Checkout code
3437
uses: actions/checkout@v3
38+
with:
39+
persist-credentials: false
3540

3641
- name: Validate ${{ matrix.skin }} skin
3742
id: validation

0 commit comments

Comments
 (0)