Skip to content

Commit 5d0a0d2

Browse files
authored
fix: prevent command injection in release workflow (#442)
* fix: prevent command injection in release workflow Mitigate remote code execution in release-build.yml where unsanitized user input could execute arbitrary commands and expose secrets. - Add input validation for semantic versioning format - Use environment variables instead of direct interpolation * address code review feedback.
1 parent daf394e commit 5d0a0d2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

.github/workflows/release-build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ jobs:
2626
with:
2727
path: ~/.gradle/wrapper
2828
key: gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
29+
- name: Validate version input
30+
run: |
31+
if [[ ! "${{ github.event.inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
32+
echo "Invalid version format. Must follow Semantic Versioning (e.g., 1.2.3, 1.2.3-alpha.1, 1.2.3+build.1)"
33+
exit 1
34+
fi
2935
- name: Build and test
30-
run: ./gradlew build -Prelease.version=${{ github.event.inputs.version }} --stacktrace
36+
run: ./gradlew build -Prelease.version="$RELEASE_VERSION" --stacktrace
3137
env:
3238
CI: true
39+
RELEASE_VERSION: ${{ github.event.inputs.version }}
3340
- name: Build and publish to sonatype
34-
run: ./gradlew final closeAndReleaseSonatypeStagingRepository -Prelease.version=${{ github.event.inputs.version }} --stacktrace
41+
run: ./gradlew final closeAndReleaseSonatypeStagingRepository -Prelease.version="$RELEASE_VERSION" --stacktrace
3542
env:
3643
CI: true
44+
RELEASE_VERSION: ${{ github.event.inputs.version }}
3745
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
3846
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
3947
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}

0 commit comments

Comments
 (0)