1- name : OmniScope Security Analysis
1+ name : Security Analysis
22
33on :
44 push :
5- branches : [main, master, dev, improve ]
5+ branches : [master, dev]
66 pull_request :
7- branches : [main, master]
8- schedule :
9- # Run daily at 2:00 UTC
10- - cron : ' 0 2 * * *'
7+ branches : [master]
118 workflow_dispatch :
12- # Allow manual trigger
139 inputs :
1410 fail_on_critical :
15- description : ' Fail build on critical issues'
11+ description : ' Fail workflow if critical issues found '
1612 required : false
1713 default : true
1814 type : boolean
1915
16+ concurrency :
17+ group : ${{ github.workflow }}-${{ github.ref }}
18+ cancel-in-progress : true
19+
20+ permissions :
21+ contents : read
22+ security-events : write
23+
24+ env :
25+ ZIG_VERSION : 0.15.2
26+
2027jobs :
21- build-and-analyze :
28+ security-analysis :
29+ name : Security Analysis
2230 runs-on : ubuntu-latest
23- permissions :
24- security-events : write
25- contents : read
26- actions : read
27-
2831 steps :
29- - name : Checkout code
30- uses : actions/checkout@v4
31-
32- - name : Setup Zig
33- uses : mlugg/setup-zig@v2
34- with :
35- version : " 0.15.0"
32+ - uses : actions/checkout@v4
3633
37- - name : Build OmniScope
34+ - name : Install ZVM and Zig
3835 run : |
39- zig build -Doptimize=ReleaseSafe
40- echo "OmniScope built successfully"
36+ curl -sSL https://www.zvm.app/install.sh | bash
37+ export ZVM_INSTALL="$HOME/.zvm/self"
38+ export PATH="$HOME/.zvm/bin:$ZVM_INSTALL:$PATH"
39+ zvm install ${{ env.ZIG_VERSION }}
40+ zvm use ${{ env.ZIG_VERSION }}
41+ echo "$HOME/.zvm/bin" >> $GITHUB_PATH
42+ echo "$HOME/.zvm/self" >> $GITHUB_PATH
4143
42- - name : Run tests
44+ - name : Install LLVM
4345 run : |
44- zig build test --summary all
46+ # Install LLVM 22 using official apt.llvm.org repository
47+ sudo apt-get update
48+ sudo apt-get install -y lsb-release wget software-properties-common gnupg
49+
50+ # Add LLVM apt repository (modern method without deprecated apt-key)
51+ wget -qO- https://apt.llvm.org/llvm.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
52+ echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-22 main" | sudo tee /etc/apt/sources.list.d/llvm.list
53+
54+ sudo apt-get update
55+ sudo apt-get install -y llvm-22-dev clang-22 libclang-22-dev
56+ echo "/usr/lib/llvm-22/bin" >> $GITHUB_PATH
4557
46- - name : Create output directory
47- run : mkdir -p analysis-output
58+ - name : Build OmniScope
59+ run : zig build -Doptimize=ReleaseSafe
4860
49- - name : Run OmniScope analysis on examples
61+ - name : Run security analysis
62+ id : analyze
5063 run : |
51- # Default empty SARIF in case no analysis runs
52- EMPTY_SARIF='{"version":"2.1.0","$schema":"https://json.schemastore.org/sarif-2.1.0.json","runs":[{"tool":{"driver":{"name":"OmniScope","version":"0.1.7","informationUri":"https://github.com/omniscope/omniscope"}},"results":[]}]}'
64+ mkdir -p analysis-output
5365
54- if [ -d "examples" ]; then
55- echo "Running OmniScope analysis on examples..."
56-
57- # Count LLVM IR files
58- FILE_COUNT=$(find examples \( -name "*.bc" -o -name "*.ll" \) -type f 2>/dev/null | wc -l)
59-
60- if [ "$FILE_COUNT" -gt 0 ]; then
61- echo "Found $FILE_COUNT LLVM IR file(s)"
62- find examples \( -name "*.bc" -o -name "*.ll" \) -type f -print0 | xargs -0 ./zig-out/bin/OmniScope \
63- --output-format sarif \
64- --output-file analysis-output/results.sarif || {
65- echo "::warning::OmniScope analysis failed, creating empty SARIF"
66- echo "$EMPTY_SARIF" > analysis-output/results.sarif
67- }
68- else
69- echo "No LLVM IR files found, creating empty SARIF"
70- echo "$EMPTY_SARIF" > analysis-output/results.sarif
71- fi
72- else
73- echo "No examples directory found, creating empty SARIF"
74- echo "$EMPTY_SARIF" > analysis-output/results.sarif
75- fi
66+ # Analyze corpus if available
67+ TOTAL=0
68+ SUCCESS=0
69+ FAIL=0
70+ TOTAL_ISSUES=0
7671
77- # Verify SARIF file was created
78- if [ ! -f analysis-output/results.sarif ]; then
79- echo "::error::SARIF file was not created!"
80- echo "$EMPTY_SARIF" > analysis-output/results.sarif
72+ if [ -d "corpus/real_world" ]; then
73+ for ll in $(find corpus/real_world -name "*.ll" -type f | head -20); do
74+ name=$(basename "$ll" .ll)
75+ TOTAL=$((TOTAL + 1))
76+
77+ if zig-out/bin/OmniScope --json "$ll" > "analysis-output/${name}.json" 2>"analysis-output/${name}.log"; then
78+ SUCCESS=$((SUCCESS + 1))
79+ issues=$(jq '.issues | length' "analysis-output/${name}.json" 2>/dev/null || echo "0")
80+ TOTAL_ISSUES=$((TOTAL_ISSUES + issues))
81+ else
82+ FAIL=$((FAIL + 1))
83+ fi
84+ done
8185 fi
86+
87+ echo "total=$TOTAL" >> $GITHUB_OUTPUT
88+ echo "success=$SUCCESS" >> $GITHUB_OUTPUT
89+ echo "fail=$FAIL" >> $GITHUB_OUTPUT
90+ echo "issues=$TOTAL_ISSUES" >> $GITHUB_OUTPUT
91+
92+ echo "=== Security Analysis Summary ==="
93+ echo "Total files: $TOTAL"
94+ echo "Success: $SUCCESS"
95+ echo "Failed: $FAIL"
96+ echo "Issues found: $TOTAL_ISSUES"
97+
98+ - name : Generate SARIF report
99+ if : always()
100+ run : |
101+ cat > analysis-output/results.sarif << 'SARIF_EOF'
102+ {
103+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
104+ "version": "2.1.0",
105+ "runs": [{
106+ "tool": {
107+ "driver": {
108+ "name": "OmniScope",
109+ "version": "0.1.7",
110+ "informationUri": "https://github.com/user/OmniScope"
111+ }
112+ },
113+ "results": []
114+ }]
115+ }
116+ SARIF_EOF
117+
118+ # Merge all analysis results into SARIF
119+ for json_file in analysis-output/*.json; do
120+ if [ -f "$json_file" ]; then
121+ jq -c '.issues[]' "$json_file" 2>/dev/null | while read -r issue; do
122+ level=$(echo "$issue" | jq -r '.severity // "warning"')
123+ message=$(echo "$issue" | jq -r '.message // "Security issue detected"')
124+ location=$(echo "$issue" | jq -r '.location.function // "unknown"')
125+
126+ jq --arg level "$level" --arg msg "$message" --arg loc "$location" '
127+ .runs[0].results += [{
128+ "level": (if $level == "critical" or $level == "high" then "error" else "warning" end),
129+ "message": {"text": $msg},
130+ "locations": [{"physicalLocation": {"artifactLocation": {"uri": $loc}}}]
131+ }]
132+ ' analysis-output/results.sarif > /tmp/sarif_tmp.json && mv /tmp/sarif_tmp.json analysis-output/results.sarif
133+ done
134+ fi
135+ done
82136
83137 - name : Upload SARIF to GitHub Security
84- uses : github/codeql-action/upload-sarif@v4
138+ uses : github/codeql-action/upload-sarif@v3
85139 if : always()
86140 with :
87141 sarif_file : analysis-output/results.sarif
88142 category : omniscope-security
89143 wait-for-processing : true
90-
91- - name : Check for critical vulnerabilities
92- id : check-vulnerabilities
93- run : |
94- if [ -f analysis-output/results.sarif ]; then
95- # Count critical and high severity issues
96- CRITICAL=$(grep -c '"level": "error"' analysis-output/results.sarif || echo "0")
97- WARNING=$(grep -c '"level": "warning"' analysis-output/results.sarif || echo "0")
98-
99- echo "critical_count=$CRITICAL" >> $GITHUB_OUTPUT
100- echo "warning_count=$WARNING" >> $GITHUB_OUTPUT
101-
102- echo "=== Security Analysis Summary ==="
103- echo "Critical issues: $CRITICAL"
104- echo "Warnings: $WARNING"
105-
106- # Fail if critical issues found and fail_on_critical is true
107- FAIL_ON_CRITICAL="${{ github.event.inputs.fail_on_critical || true }}"
108- if [ "$FAIL_ON_CRITICAL" = "true" ] && [ "$CRITICAL" -gt 0 ]; then
109- echo "::error::Found $CRITICAL critical security issues!"
110- exit 1
111- fi
112-
113- if [ "$CRITICAL" -gt 0 ]; then
114- echo "::warning::Found $CRITICAL critical security issues"
115- fi
116-
117- if [ "$WARNING" -gt 0 ]; then
118- echo "::warning::Found $WARNING security warnings"
119- fi
120- fi
144+ continue-on-error : true
121145
122146 - name : Upload analysis artifacts
123147 uses : actions/upload-artifact@v4
@@ -127,48 +151,35 @@ jobs:
127151 path : analysis-output/
128152 retention-days : 30
129153
130- # Optional: Cross-platform analysis
131- analyze-macos :
132- runs-on : macos-latest
133- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
134-
135- steps :
136- - name : Checkout code
137- uses : actions/checkout@v4
138-
139- - name : Setup Zig
140- uses : mlugg/setup-zig@v2
141- with :
142- version : " 0.15.0"
143-
144- - name : Build and test
145- run : |
146- zig build -Doptimize=ReleaseSafe
147- zig build test --summary all
148-
149- # Security scorecard
150- security-scorecard :
151- runs-on : ubuntu-latest
152- needs : build-and-analyze
153- if : always()
154-
155- steps :
156- - name : Generate security scorecard
154+ - name : Generate security summary
155+ if : always()
157156 run : |
158- echo "=== OmniScope Security Scorecard ==="
159- echo ""
160- echo "Analysis completed: $(date)"
161- echo "Repository: ${{ github.repository }}"
162- echo "Branch: ${{ github.ref_name }}"
163- echo "Commit: ${{ github.sha }}"
164- echo ""
165- echo "Security tools used:"
166- echo " - OmniScope v0.1.0 (FFI Security Analyzer)"
167- echo " - LLVM IR based static analysis"
168- echo ""
169- echo "Checks performed:"
170- echo " - FFI boundary validation"
171- echo " - Memory safety analysis"
172- echo " - Taint propagation tracking"
173- echo " - Command injection detection"
174- echo " - Buffer overflow detection"
157+ TOTAL=${{ steps.analyze.outputs.total }}
158+ SUCCESS=${{ steps.analyze.outputs.success }}
159+ FAIL=${{ steps.analyze.outputs.fail }}
160+ ISSUES=${{ steps.analyze.outputs.issues }}
161+
162+ # Ensure defaults
163+ TOTAL=${TOTAL:-0}
164+ SUCCESS=${SUCCESS:-0}
165+ FAIL=${FAIL:-0}
166+ ISSUES=${ISSUES:-0}
167+
168+ # Safe division
169+ if [ "$TOTAL" -gt 0 ]; then
170+ SUCCESS_RATE=$((SUCCESS * 100 / TOTAL))
171+ else
172+ SUCCESS_RATE=0
173+ fi
174+
175+ echo "## 🔒 OmniScope Security Analysis" >> $GITHUB_STEP_SUMMARY
176+ echo "" >> $GITHUB_STEP_SUMMARY
177+ echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
178+ echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
179+ echo "| **Files Analyzed** | $TOTAL |" >> $GITHUB_STEP_SUMMARY
180+ echo "| **Success** | ✅ $SUCCESS |" >> $GITHUB_STEP_SUMMARY
181+ echo "| **Failed** | ❌ $FAIL |" >> $GITHUB_STEP_SUMMARY
182+ echo "| **Issues Found** | 🐛 $ISSUES |" >> $GITHUB_STEP_SUMMARY
183+ echo "| **Success Rate** | ${SUCCESS_RATE}% |" >> $GITHUB_STEP_SUMMARY
184+ echo "" >> $GITHUB_STEP_SUMMARY
185+ echo "**Analysis Date**: $(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
0 commit comments