-
-
Notifications
You must be signed in to change notification settings - Fork 10
109 lines (100 loc) · 3.74 KB
/
security-sast-common.yml
File metadata and controls
109 lines (100 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Common SAST (Semgrep)
on:
workflow_call:
inputs:
config:
description: 'Semgrep config (e.g., p/security-audit, p/golang)'
type: string
default: 'p/security-audit'
extra_config:
description: 'Additional Semgrep configs (space-separated)'
type: string
default: ''
outputs:
findings:
description: 'Total Semgrep findings'
value: ${{ jobs.semgrep.outputs.findings }}
high:
description: 'HIGH/ERROR severity findings'
value: ${{ jobs.semgrep.outputs.high }}
medium:
description: 'MEDIUM/WARNING severity findings'
value: ${{ jobs.semgrep.outputs.medium }}
jobs:
semgrep:
name: Semgrep SAST
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
security-events: write
outputs:
findings: ${{ steps.scan.outputs.findings }}
high: ${{ steps.scan.outputs.high }}
medium: ${{ steps.scan.outputs.medium }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Run Semgrep
id: scan
env:
SEMGREP_CONFIG: ${{ inputs.config }}
SEMGREP_EXTRA_CONFIG: ${{ inputs.extra_config }}
run: |
EXTRA_ARG=""
if [ -n "$SEMGREP_EXTRA_CONFIG" ]; then
EXTRA_ARG="--config=$SEMGREP_EXTRA_CONFIG"
fi
docker run --rm -v "$PWD:/src" -w /src semgrep/semgrep:1.156.0 \
semgrep scan \
--config="$SEMGREP_CONFIG" \
$EXTRA_ARG \
--json --output=semgrep.json \
--sarif --sarif-output=semgrep.sarif \
. || true
- name: Parse results
id: parse
run: |
if [ -f semgrep.json ]; then
FINDINGS=$(jq '.results | length' semgrep.json 2>/dev/null || echo "0")
# Semgrep uses "ERROR" for high severity, "WARNING" for medium
HIGH=$(jq '[.results[]? | select(.extra.severity == "ERROR")] | length' semgrep.json 2>/dev/null || echo "0")
MEDIUM=$(jq '[.results[]? | select(.extra.severity == "WARNING")] | length' semgrep.json 2>/dev/null || echo "0")
echo "findings=$FINDINGS" >> $GITHUB_OUTPUT
echo "high=$HIGH" >> $GITHUB_OUTPUT
echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
if [ "$HIGH" -gt 0 ]; then
echo "::error::$HIGH HIGH severity Semgrep finding(s)"
fi
if [ "$MEDIUM" -gt 0 ]; then
echo "::warning::$MEDIUM MEDIUM severity Semgrep finding(s)"
fi
else
echo "findings=0" >> $GITHUB_OUTPUT
echo "high=0" >> $GITHUB_OUTPUT
echo "medium=0" >> $GITHUB_OUTPUT
fi
# Write summary
echo "### Semgrep Results" >> $GITHUB_STEP_SUMMARY
echo "| Severity | Count |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| HIGH | ${HIGH:-0} |" >> $GITHUB_STEP_SUMMARY
echo "| MEDIUM | ${MEDIUM:-0} |" >> $GITHUB_STEP_SUMMARY
echo "| **Total** | **${FINDINGS:-0}** |" >> $GITHUB_STEP_SUMMARY
- name: Upload SARIF
if: hashFiles('semgrep.sarif') != ''
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
with:
sarif_file: semgrep.sarif
category: semgrep
continue-on-error: true
- name: Upload artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: always()
with:
name: semgrep-results
path: |
semgrep.json
semgrep.sarif
retention-days: 30
if-no-files-found: ignore