Skip to content

Commit 15c6b8b

Browse files
Zohayb BhattiZohayb Bhatti
authored andcommitted
fix: Replace template injection with secure context.payload access
- Replace github.event.workflow_run.head_sha template injection with context.payload.workflow_run?.head_sha - Add SHA format validation (40 hex characters) before use - Fixes Kusari security scanner template injection vulnerabilities - Addresses issues in build-binaries.yml, docker-push.yml, and security-scan.yml
1 parent 049280e commit 15c6b8b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.github/workflows/build-binaries.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ jobs:
4444
uses: actions/github-script@v7
4545
with:
4646
script: |
47+
const headSha = context.payload.workflow_run?.head_sha;
48+
if (!headSha || !/^[a-f0-9]{40}$/i.test(headSha)) {
49+
core.setFailed('Invalid head SHA');
50+
return;
51+
}
4752
const { data: runs } = await github.rest.actions.listWorkflowRuns({
4853
owner: context.repo.owner,
4954
repo: context.repo.repo,
5055
workflow_id: 'lint.yaml',
51-
head_sha: '${{ github.event.workflow_run.head_sha }}',
56+
head_sha: headSha,
5257
per_page: 1
5358
});
5459
if (runs.workflow_runs.length > 0 && runs.workflow_runs[0].conclusion !== 'success') {

.github/workflows/docker-push.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ jobs:
3030
uses: actions/github-script@v7
3131
with:
3232
script: |
33+
const headSha = context.payload.workflow_run?.head_sha;
34+
if (!headSha || !/^[a-f0-9]{40}$/i.test(headSha)) {
35+
core.setFailed('Invalid head SHA');
36+
return;
37+
}
3338
const { data: runs } = await github.rest.actions.listWorkflowRuns({
3439
owner: context.repo.owner,
3540
repo: context.repo.repo,
3641
workflow_id: 'lint.yaml',
37-
head_sha: '${{ github.event.workflow_run.head_sha }}',
42+
head_sha: headSha,
3843
per_page: 1
3944
});
4045
if (runs.workflow_runs.length > 0 && runs.workflow_runs[0].conclusion !== 'success') {

.github/workflows/security-scan.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ jobs:
2424
uses: actions/github-script@v7
2525
with:
2626
script: |
27+
const headSha = context.payload.workflow_run?.head_sha;
28+
if (!headSha || !/^[a-f0-9]{40}$/i.test(headSha)) {
29+
core.setFailed('Invalid head SHA');
30+
return;
31+
}
2732
const { data: runs } = await github.rest.actions.listWorkflowRuns({
2833
owner: context.repo.owner,
2934
repo: context.repo.repo,
3035
workflow_id: 'lint.yaml',
31-
head_sha: '${{ github.event.workflow_run.head_sha }}',
36+
head_sha: headSha,
3237
per_page: 1
3338
});
3439
if (runs.workflow_runs.length > 0 && runs.workflow_runs[0].conclusion !== 'success') {

0 commit comments

Comments
 (0)