Skip to content

Commit 2244f92

Browse files
authored
Add static check for github.event.inputs in run steps (#1295)
See aws-observability/aws-otel-js-instrumentation#339 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent e13ab16 commit 2244f92

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/pr-build.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
- "release/v*"
1313
env:
1414
TEST_TAG: public.ecr.aws/aws-observability/adot-autoinstrumentation-java:test-v2
15+
USER: ${{ github.event.pull_request.user.login }}
16+
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
1517

1618
jobs:
1719
static-code-checks:
@@ -25,18 +27,18 @@ jobs:
2527
if: always()
2628
run: |
2729
# Check if PR is from workflows bot or dependabot
28-
if [[ "${{ github.event.pull_request.user.login }}" == "aws-application-signals-bot" ]]; then
30+
if [[ "${{ env.USER }}" == "aws-application-signals-bot" ]]; then
2931
echo "Skipping check: PR from aws-application-signals-bot"
3032
exit 0
3133
fi
3234
33-
if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]]; then
35+
if [[ "${{ env.USER }}" == "dependabot[bot]" ]]; then
3436
echo "Skipping check: PR from dependabot"
3537
exit 0
3638
fi
3739
3840
# Check for skip changelog label
39-
if echo '${{ toJSON(github.event.pull_request.labels.*.name) }}' | jq -r '.[]' | grep -q "skip changelog"; then
41+
if echo '${{ env.LABELS }}' | jq -r '.[]' | grep -q "skip changelog"; then
4042
echo "Skipping check: skip changelog label found"
4143
exit 0
4244
fi
@@ -69,6 +71,31 @@ jobs:
6971
7072
echo "No versioned actions found in changed files"
7173
74+
- name: Check for github.event in run steps
75+
if: always()
76+
run: |
77+
# Get changed GitHub workflow/action files
78+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
79+
80+
if [ -n "$CHANGED_FILES" ]; then
81+
VIOLATIONS=""
82+
for file in $CHANGED_FILES; do
83+
# Extract all 'run' step values excluding this validation step
84+
RUN_STEPS=$(yq eval '.. | select(has("run") and has("name") and .name != "Check for github.event in run steps") | .run' "$file" 2>/dev/null || echo "")
85+
if echo "$RUN_STEPS" | grep -q "github\.event\."; then
86+
VIOLATIONS="$VIOLATIONS$file: Contains github.event.* in run step\n"
87+
fi
88+
done
89+
90+
if [ -n "$VIOLATIONS" ]; then
91+
echo -e "Found github.event.* usage in run steps. This can lead to script injection vulnerabilities:"
92+
echo -e "$VIOLATIONS"
93+
exit 1
94+
fi
95+
fi
96+
97+
echo "No github.event.inputs usage found in run steps"
98+
7299
testpatch:
73100
name: Test patches applied to dependencies
74101
runs-on: aws-otel-java-instrumentation_ubuntu-latest_32-core
@@ -100,7 +127,7 @@ jobs:
100127

101128
build:
102129
name: Build on ${{ matrix.os }}
103-
runs-on: ${{ matrix.os }}
130+
runs-on: ${{ matrix.os }}
104131
strategy:
105132
matrix:
106133
os:

0 commit comments

Comments
 (0)