Security fix: prevent validation script injection in PRs
This commit is contained in:
@@ -2,15 +2,21 @@ name: Validate Plugin PR
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
paths:
|
|
||||||
- 'plugins/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
validate:
|
validate:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout base branch (main) for validation scripts
|
||||||
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
|
ref: main
|
||||||
|
path: base
|
||||||
|
|
||||||
|
- name: Checkout PR branch for plugin files
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: pr
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -21,11 +27,26 @@ jobs:
|
|||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
run: |
|
run: |
|
||||||
|
cd pr
|
||||||
echo "files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^plugins/' || echo '')" >> $GITHUB_OUTPUT
|
echo "files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^plugins/' || echo '')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Validate PR
|
- name: Block attempts to modify infrastructure
|
||||||
run: |
|
run: |
|
||||||
node .gitea/scripts/validate-pr.js "${{ github.event.pull_request.user.login }}" "${{ steps.changed-files.outputs.files }}"
|
cd pr
|
||||||
|
INFRA_CHANGES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^\.gitea/' || echo '')
|
||||||
|
if [ -n "$INFRA_CHANGES" ]; then
|
||||||
|
echo "❌ ERROR: PRs cannot modify .gitea/ directory files"
|
||||||
|
echo "Changed infrastructure files:"
|
||||||
|
echo "$INFRA_CHANGES"
|
||||||
|
echo ""
|
||||||
|
echo "Only plugins/ directory changes are allowed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Validate PR (using trusted validation script from main)
|
||||||
|
run: |
|
||||||
|
node base/.gitea/scripts/validate-pr.js "${{ github.event.pull_request.user.login }}" "${{ steps.changed-files.outputs.files }}"
|
||||||
|
working-directory: pr
|
||||||
|
|
||||||
- name: Auto-merge PR
|
- name: Auto-merge PR
|
||||||
if: success()
|
if: success()
|
||||||
|
|||||||
Reference in New Issue
Block a user