fix code injection via template expansion

github.event.pull_request.head.repo.full_name may expand into attacker-controllable code

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-03-17 13:40:02 +01:00
parent 1907bca23a
commit b069b11219
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -30,34 +30,45 @@ jobs:
steps: steps:
- name: Setup variables - name: Setup variables
id: get-vars id: get-vars
env:
PR_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPO: ${{ github.repository }}
run: | run: |
if [ -z "$GITHUB_HEAD_REF" ]; then if [ -z "$GITHUB_HEAD_REF" ]; then
# push # push
{ {
echo "branch=$GITHUB_REF_NAME" echo "branch=$GITHUB_REF_NAME"
echo "pr=$GITHUB_RUN_ID" echo "pr=$GITHUB_RUN_ID"
echo "repo=${{ github.repository }}" echo "repo=$GITHUB_REPO"
} >> "$GITHUB_OUTPUT" } >> "$GITHUB_OUTPUT"
else else
# pull request # pull request
SAFE_REPO_NAME=$(echo "$PR_REPO_FULL_NAME" | sed 's/[^a-zA-Z0-9._-]//g')
SAFE_BRANCH=$(echo "$GITHUB_HEAD_REF" | sed 's/[^a-zA-Z0-9._-]//g')
{ {
echo "branch=$GITHUB_HEAD_REF" printf 'branch=%s\n' "$SAFE_BRANCH"
echo "pr=${{ github.event.pull_request.number }}" printf 'pr=%s\n' "$PR_NUMBER"
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" printf 'repo=%s\n' "$SAFE_REPO_NAME"
} >> "$GITHUB_OUTPUT" } >> "$GITHUB_OUTPUT"
fi fi
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with: with:
repository: ${{ steps.get-vars.outputs.repo }} repository: ${{ steps.get-vars.outputs.repo }}
ref: ${{ steps.get-vars.outputs.branch }} ref: ${{ steps.get-vars.outputs.branch }}
- name: Set up JDK 17 - name: Set up JDK 17
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
with: with:
distribution: "temurin" distribution: "temurin"
java-version: 17 java-version: 17
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt install python3-defusedxml sudo apt install python3-defusedxml
- name: Run analysis wrapper - name: Run analysis wrapper
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}