Skip to content

Commit 5c6ccd5

Browse files
fix(security): resolve GitHub code scanning alert #1 (#291)
* fix(ci): scope workflow permissions to job level and use Trivy action for SBOM generation Move permissions from workflow level to job level in docs-preview workflow for principle of least privilege. Replace manual Trivy installation and CLI commands with aquasecurity/trivy-action@0.29.0 for SBOM generation in release workflow. * chore: fux
1 parent 3058ca6 commit 5c6ccd5

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

.github/workflows/docs-preview.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ on:
1616
- master
1717
- main
1818

19-
permissions:
20-
contents: write # Required to push to gh-pages branch
21-
pages: write
22-
id-token: write
23-
pull-requests: write
24-
actions: read
25-
2619
jobs:
2720
# Build and deploy docs preview for opened/updated PRs
2821
build-preview:
29-
if: github.event.action != 'closed'
22+
permissions:
23+
contents: write # Push to gh-pages branch
24+
pull-requests: write # Create/update preview comment
25+
# SECURITY: Only run on pull_request trigger (not pull_request_target) to prevent
26+
# untrusted fork PRs from executing code with write permissions (RCE vulnerability)
27+
if: github.event_name == 'pull_request' && github.event.action != 'closed'
3028
runs-on: ubuntu-latest
3129
steps:
3230
- name: 📂 Checkout PR code
@@ -126,6 +124,9 @@ jobs:
126124
127125
# Clean up preview when PR is closed/merged
128126
cleanup-preview:
127+
permissions:
128+
contents: write # Push to gh-pages branch
129+
pull-requests: write # Update comment on cleanup
129130
if: github.event.action == 'closed'
130131
runs-on: ubuntu-latest
131132
steps:

.github/workflows/release.yaml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,19 @@ jobs:
4646
--bare \
4747
--tags=${{ github.ref_name }},latest
4848
49-
- name: 🔍 Install Trivy
50-
run: |
51-
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
52-
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
53-
sudo apt-get update
54-
sudo apt-get install trivy
55-
5649
- name: 📋 Generate SBOM (SPDX format)
57-
run: |
58-
trivy image \
59-
--format spdx-json \
60-
--output sbom-spdx.json \
61-
${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
50+
uses: aquasecurity/trivy-action@0.29.0
51+
with:
52+
image-ref: ${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
53+
format: spdx-json
54+
output: sbom-spdx.json
6255

6356
- name: 📋 Generate SBOM (CycloneDX format)
64-
run: |
65-
trivy image \
66-
--format cyclonedx \
67-
--output sbom-cyclonedx.json \
68-
${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
57+
uses: aquasecurity/trivy-action@0.29.0
58+
with:
59+
image-ref: ${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
60+
format: cyclonedx
61+
output: sbom-cyclonedx.json
6962

7063
- name: 📦 Upload SBOMs to release
7164
uses: softprops/action-gh-release@v2

0 commit comments

Comments
 (0)