Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab2e7b4

Browse files
committed
security: Fix GitHub Actions shell injection vulnerability
- Use environment variables instead of direct interpolation - Prevent shell injection through github context data - Follow GitHub security best practices
1 parent ac094d4 commit ab2e7b4

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/cd.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ jobs:
4545

4646
- name: Determine deployment environment
4747
id: determine-env
48+
env:
49+
# Use environment variable to prevent shell injection
50+
GITHUB_EVENT_NAME: ${{ github.event_name }}
51+
GITHUB_REF: ${{ github.ref }}
52+
GITHUB_INPUT_ENVIRONMENT: ${{ github.event.inputs.environment }}
4853
run: |
49-
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
50-
echo "environment=${{ github.event.inputs.environment }}" >> $GITHUB_OUTPUT
51-
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
54+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
55+
echo "environment=$GITHUB_INPUT_ENVIRONMENT" >> $GITHUB_OUTPUT
56+
elif [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
5257
echo "environment=staging" >> $GITHUB_OUTPUT
53-
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
58+
elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then
5459
echo "environment=production" >> $GITHUB_OUTPUT
5560
else
5661
echo "environment=staging" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)