Skip to content

Commit e9fd9c3

Browse files
authored
ci: resolve CodeQL code-scanning alerts in workflows (#1825)
1 parent 22c2aae commit e9fd9c3

16 files changed

Lines changed: 106 additions & 13 deletions

.github/workflows/bench.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}${{ github.event_name == 'pull_request_review' && format('-review-{0}', github.run_id) || '' }}
1111
cancel-in-progress: true
1212

13+
# Least-privilege default: no job in this workflow writes to the repo.
14+
permissions:
15+
contents: read
16+
1317
jobs:
1418
file-changes:
1519
name: Detect File Changes
1620
if: >
1721
github.event_name != 'pull_request_review' ||
1822
github.event.review.user.type != 'Bot'
23+
# Job-level permissions replace the workflow default outright rather than
24+
# merging with it, so contents must be restated here. paths-filter reads the
25+
# PR's changed-file list via pulls.listFiles; this is the only job that needs
26+
# it, so it is granted here instead of workflow-wide.
27+
permissions:
28+
contents: read
29+
pull-requests: read
1930
runs-on: 'ubuntu-latest'
2031
outputs:
2132
checkall: ${{ steps.changes.outputs.checkall }}

.github/workflows/claude-code-review.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,17 @@ jobs:
5858
exit 1
5959
fi
6060
61-
PR_HEAD_REF="$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName --jq .headRefName)"
62-
6361
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
64-
echo "pr_head_ref=$PR_HEAD_REF" >> "$GITHUB_OUTPUT"
6562
63+
# Base repo only. This job is privileged (pull_request_target / issue_comment:
64+
# it holds secrets and a write-capable token), so the PR head is never checked
65+
# out or fetched here. The diff and per-file context are pulled through the gh
66+
# API in later steps and treated purely as data.
6667
- name: Checkout base repo
6768
uses: actions/checkout@v5
6869
with:
6970
fetch-depth: 0
7071

71-
- name: Fetch PR head
72-
shell: bash
73-
env:
74-
PR_NUMBER: ${{ steps.mode.outputs.pr_number }}
75-
run: |
76-
set -euo pipefail
77-
# Fetch the PR merge ref — works for both same-repo and fork PRs
78-
# (fork branches don't exist on origin, but pull/<n>/head always does)
79-
git fetch origin "pull/${PR_NUMBER}/head"
80-
8172
- name: Resolve review state
8273
id: state
8374
shell: bash

.github/workflows/cleanliness.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

13+
# Least-privilege default: no job in this workflow writes to the repo.
14+
permissions:
15+
contents: read
16+
1317
jobs:
1418
file-changes:
1519
name: Detect File Changes
20+
# Job-level permissions replace the workflow default outright rather than
21+
# merging with it, so contents must be restated here. paths-filter reads the
22+
# PR's changed-file list via pulls.listFiles; this is the only job that needs
23+
# it, so it is granted here instead of workflow-wide.
24+
permissions:
25+
contents: read
26+
pull-requests: read
1627
runs-on: 'ubuntu-latest'
1728
outputs:
1829
checkall: ${{ steps.changes.outputs.checkall }}

.github/workflows/convergence.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ on:
1010
env:
1111
OMPI_MCA_rmaps_base_oversubscribe: 1
1212

13+
# Least-privilege default: no job in this workflow writes to the repo.
14+
permissions:
15+
contents: read
16+
1317
jobs:
1418
file-changes:
1519
name: Detect File Changes
20+
# Job-level permissions replace the workflow default outright rather than
21+
# merging with it, so contents must be restated here. paths-filter reads the
22+
# PR's changed-file list via pulls.listFiles; this is the only job that needs
23+
# it, so it is granted here instead of workflow-wide.
24+
permissions:
25+
contents: read
26+
pull-requests: read
1627
runs-on: ubuntu-latest
1728
outputs:
1829
checkall: ${{ steps.changes.outputs.checkall }}

.github/workflows/coverage-health.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
schedule:
55
- cron: '0 7 * * *' # daily; loud if the refresh stopped working
66
workflow_dispatch:
7+
# Least-privilege default: no job in this workflow writes to the repo.
8+
permissions:
9+
contents: read
10+
711
jobs:
812
health:
913
if: github.repository == 'MFlowCode/MFC'

.github/workflows/coverage.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
1212
cancel-in-progress: true
1313

14+
# Least-privilege default: no job in this workflow writes to the repo.
15+
permissions:
16+
contents: read
17+
1418
jobs:
1519
file-changes:
1620
name: Detect File Changes
21+
# Job-level permissions replace the workflow default outright rather than
22+
# merging with it, so contents must be restated here. paths-filter reads the
23+
# PR's changed-file list via pulls.listFiles; this is the only job that needs
24+
# it, so it is granted here instead of workflow-wide.
25+
permissions:
26+
contents: read
27+
pull-requests: read
1728
runs-on: 'ubuntu-latest'
1829
outputs:
1930
checkall: ${{ steps.changes.outputs.checkall }}

.github/workflows/docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches: [master]
99
pull_request:
1010

11+
# Least-privilege default: no job in this workflow writes to the repo.
12+
permissions:
13+
contents: read
14+
1115
jobs:
1216
build:
1317
name: Build & Verify

.github/workflows/formatting.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
pull_request:
77
workflow_dispatch:
88

9+
# Least-privilege default: no job in this workflow writes to the repo.
10+
permissions:
11+
contents: read
12+
913
jobs:
1014
docs:
1115
name: Formatting

.github/workflows/fp-stability.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,20 @@ on:
3535
types: [opened, synchronize, reopened, ready_for_review]
3636
workflow_dispatch:
3737

38+
# Least-privilege default: no job in this workflow writes to the repo.
39+
permissions:
40+
contents: read
41+
3842
jobs:
3943
file-changes:
4044
name: Detect File Changes
45+
# Job-level permissions replace the workflow default outright rather than
46+
# merging with it, so contents must be restated here. paths-filter reads the
47+
# PR's changed-file list via pulls.listFiles; this is the only job that needs
48+
# it, so it is granted here instead of workflow-wide.
49+
permissions:
50+
contents: read
51+
pull-requests: read
4152
runs-on: ubuntu-latest
4253
outputs:
4354
checkall: ${{ steps.changes.outputs.checkall }}

.github/workflows/homebrew-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ on:
2121
type: boolean
2222
default: false
2323

24+
# Least-privilege default: no job in this workflow writes to the repo.
25+
permissions:
26+
contents: read
27+
2428
jobs:
2529
update-homebrew-tap:
2630
name: Update homebrew-mfc tap

0 commit comments

Comments
 (0)