Skip to content

Commit a96bcef

Browse files
committed
claude
Signed-off-by: Anas Nashif <[email protected]>
1 parent 7d07c75 commit a96bcef

File tree

1 file changed

+64
-17
lines changed

1 file changed

+64
-17
lines changed

.github/workflows/manifest.yml

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,93 @@
11
name: Manifest
2+
# Uses pull_request_target but with careful security controls
23
on:
3-
pull_request:
4+
pull_request_target:
5+
paths:
6+
- 'west.yml'
47

58
permissions:
69
contents: read
710

811
jobs:
9-
contribs:
12+
manifest-validation:
1013
runs-on: ubuntu-22.04
14+
name: Validate Manifest
1115
permissions:
1216
pull-requests: write # to create/update pull request comments
13-
issues: write
14-
name: Manifest
17+
contents: read
1518
steps:
16-
- name: Checkout the code
19+
# SECURITY CRITICAL: First checkout the base repo code WITHOUT using untrusted code
20+
- name: Checkout base repository
1721
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1822
with:
19-
path: zephyrproject/zephyr
20-
#ref: ${{ github.event.pull_request.head.sha }}
23+
ref: ${{ github.base_ref }}
24+
path: base-repo
2125
fetch-depth: 0
2226
persist-credentials: false
2327

24-
- name: west setup
25-
env:
26-
BASE_REF: ${{ github.base_ref }}
27-
working-directory: zephyrproject/zephyr
28+
# SECURITY: Then fetch PR data - only checking out the specific manifest file
29+
- name: Fetch PR Manifest
2830
run: |
29-
git checkout ${{ github.event.pull_request.head.sha }}
30-
pip install west
31-
git config --global user.email "[email protected]"
32-
git config --global user.name "Your Name"
31+
# Safely get the PR's west.yml file without executing any PR code
32+
PR_SHA="${{ github.event.pull_request.head.sha }}"
33+
PR_REPO="${{ github.event.pull_request.head.repo.full_name }}"
34+
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
35+
36+
echo "Fetching west.yml from PR $PR_SHA from $PR_REPO branch $PR_BRANCH"
37+
mkdir -p pr-repo
38+
curl -s -L "https://raw.githubusercontent.com/$PR_REPO/$PR_SHA/west.yml" > pr-repo/west.yml
39+
40+
# Validate the file was downloaded successfully
41+
if [ ! -s "pr-repo/west.yml" ]; then
42+
echo "Failed to fetch west.yml from PR"
43+
exit 1
44+
fi
45+
46+
- name: Validate manifest changes
47+
run: |
48+
# Basic manifest file validation
49+
echo "Validating west.yml format..."
50+
python -c "import yaml; yaml.safe_load(open('pr-repo/west.yml'))" || {
51+
echo "Invalid YAML format in west.yml"
52+
exit 1
53+
}
54+
55+
# Compare manifest files to show changes
56+
echo "Comparing manifest changes..."
57+
diff -u base-repo/west.yml pr-repo/west.yml || true
58+
59+
- name: Create minimal repo structure for west
60+
run: |
61+
# Create a minimal structure required by west without executing PR code
62+
mkdir -p pr-repo/.git
63+
cp -r base-repo/.git/* pr-repo/.git/
64+
65+
- name: West setup
66+
run: |
67+
pip install --user west
68+
git config --global user.email "[email protected]"
69+
git config --global user.name "GitHub Actions"
70+
71+
# Initialize west with the manifest file we explicitly downloaded
72+
cd pr-repo
3373
west init -l . || true
3474
35-
- name: Manifest
75+
# After creating necessary environment above, run the action
76+
- name: Run manifest action with restricted token
3677
uses: zephyrproject-rtos/action-manifest@cb8f6fba6f20b5f8649bd573e80a7583a239894c # v1.7.0
3778
with:
3879
github-token: ${{ secrets.GITHUB_TOKEN }}
3980
manifest-path: 'west.yml'
40-
checkout-path: 'zephyrproject/zephyr'
81+
checkout-path: 'pr-repo'
4182
use-tree-checkout: 'true'
4283
check-impostor-commits: 'true'
4384
label-prefix: 'manifest-'
4485
verbosity-level: '1'
4586
labels: 'manifest'
4687
dnm-labels: 'DNM (manifest)'
88+
89+
# Optional: Clean up sensitive data after running
90+
- name: Clean up
91+
if: always()
92+
run: |
93+
rm -rf pr-repo base-repo

0 commit comments

Comments
 (0)