|
1 | | -# SPDX-License-Identifier: MPL-2.0 |
2 | | -# CodeQL Security Analysis - Strict Mode |
3 | | -# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors |
4 | | - |
5 | | -name: "CodeQL Security Analysis" |
| 1 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +name: CodeQL Security Analysis |
6 | 3 |
|
7 | 4 | on: |
8 | 5 | push: |
9 | | - branches: [main, develop] |
| 6 | + branches: [main, master] |
10 | 7 | pull_request: |
11 | | - branches: [main] |
| 8 | + branches: [main, master] |
12 | 9 | schedule: |
13 | | - # Run daily at 00:00 UTC for thorough security coverage |
14 | | - - cron: "0 0 * * *" |
15 | | - workflow_dispatch: |
| 10 | + - cron: '0 6 * * 1' |
16 | 11 |
|
17 | | -permissions: |
18 | | - actions: read |
19 | | - contents: read |
20 | | - security-events: write |
| 12 | +permissions: read-all |
21 | 13 |
|
22 | 14 | jobs: |
23 | 15 | analyze: |
24 | | - name: CodeQL Analysis |
25 | 16 | runs-on: ubuntu-latest |
26 | 17 | permissions: |
27 | | - security-events: write |
28 | 18 | contents: read |
29 | | - |
| 19 | + security-events: write |
30 | 20 | strategy: |
31 | | - fail-fast: true # Fail immediately on security issues |
| 21 | + fail-fast: false |
32 | 22 | matrix: |
33 | 23 | include: |
34 | 24 | - language: actions |
35 | 25 | build-mode: none |
36 | 26 |
|
37 | 27 | steps: |
38 | | - - name: Checkout repository |
39 | | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
40 | 30 |
|
41 | 31 | - name: Initialize CodeQL |
42 | | - uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v3 |
| 32 | + uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.28.1 |
43 | 33 | with: |
44 | 34 | languages: ${{ matrix.language }} |
45 | | - # Maximum security coverage |
46 | | - queries: +security-extended,security-and-quality,security-experimental |
47 | | - |
48 | | - - name: Autobuild |
49 | | - uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v3 |
| 35 | + build-mode: ${{ matrix.build-mode }} |
50 | 36 |
|
51 | 37 | - name: Perform CodeQL Analysis |
52 | | - uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v3 |
| 38 | + uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.28.1 |
53 | 39 | with: |
54 | 40 | category: "/language:${{ matrix.language }}" |
55 | | - # Fail on any high or critical severity issues |
56 | | - upload: true |
57 | | - |
58 | | - # OCaml-specific security checks - STRICT MODE |
59 | | - ocaml-security: |
60 | | - name: OCaml Security Checks (Strict) |
61 | | - runs-on: ubuntu-latest |
62 | | - permissions: |
63 | | - contents: read |
64 | | - |
65 | | - steps: |
66 | | - - name: Checkout repository |
67 | | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
68 | | - |
69 | | - - name: Set up OCaml |
70 | | - uses: ocaml/setup-ocaml@7c185f622998a008ba1b296d2d7c64e235629c23 # v3.6.1 |
71 | | - with: |
72 | | - ocaml-compiler: "4.14.x" |
73 | | - |
74 | | - - name: Install dependencies |
75 | | - run: | |
76 | | - opam install . --deps-only --with-test -y |
77 | | - working-directory: engines/rescript-wasm |
78 | | - |
79 | | - - name: Build with strict warnings |
80 | | - run: | |
81 | | - opam exec -- dune build @all --force |
82 | | - working-directory: engines/rescript-wasm |
83 | | - |
84 | | - - name: Run all tests (must pass) |
85 | | - run: | |
86 | | - opam exec -- dune test |
87 | | - working-directory: engines/rescript-wasm |
88 | | - |
89 | | - - name: Security audit - unsafe patterns (MUST PASS) |
90 | | - run: | |
91 | | - echo "=========================================" |
92 | | - echo "Security Audit - Unsafe Patterns" |
93 | | - echo "=========================================" |
94 | | - ERRORS=0 |
95 | | -
|
96 | | - # Check for Obj.magic usage (type safety bypass) |
97 | | - if grep -rn "Obj\.magic" engines/rescript-wasm/lib/; then |
98 | | - echo "::error::CRITICAL: Obj.magic usage found - type safety violation" |
99 | | - ERRORS=$((ERRORS + 1)) |
100 | | - fi |
101 | | -
|
102 | | - # Check for Marshal usage (potential code execution) |
103 | | - if grep -rn "Marshal\." engines/rescript-wasm/lib/; then |
104 | | - echo "::error::CRITICAL: Marshal usage found - code execution risk" |
105 | | - ERRORS=$((ERRORS + 1)) |
106 | | - fi |
107 | | -
|
108 | | - # Check for shell command execution |
109 | | - if grep -rn "Sys\.command\|Unix\.system\|Unix\.open_process" engines/rescript-wasm/lib/; then |
110 | | - echo "::error::CRITICAL: Shell command execution found - injection risk" |
111 | | - ERRORS=$((ERRORS + 1)) |
112 | | - fi |
113 | | -
|
114 | | - # Check for unsafe file operations |
115 | | - if grep -rn "open_in\|open_out" engines/rescript-wasm/lib/ | grep -v "In_channel\|Out_channel"; then |
116 | | - echo "::warning::Found legacy file operations - consider using In_channel/Out_channel" |
117 | | - fi |
118 | | -
|
119 | | - # Check for eval-like constructs |
120 | | - if grep -rn "Dynlink\|Toploop" engines/rescript-wasm/lib/; then |
121 | | - echo "::error::CRITICAL: Dynamic code loading found - security risk" |
122 | | - ERRORS=$((ERRORS + 1)) |
123 | | - fi |
124 | | -
|
125 | | - if [ $ERRORS -gt 0 ]; then |
126 | | - echo "=========================================" |
127 | | - echo "FAILED: Found $ERRORS critical security issues" |
128 | | - echo "=========================================" |
129 | | - exit 1 |
130 | | - fi |
131 | | -
|
132 | | - echo "=========================================" |
133 | | - echo "PASSED: No critical security issues found" |
134 | | - echo "=========================================" |
135 | | -
|
136 | | - - name: Security audit - integer overflow risks |
137 | | - run: | |
138 | | - echo "=== Checking for integer overflow risks ===" |
139 | | - # Check for i31 operations that might overflow |
140 | | - if grep -rn "I32Const.*[0-9]\{10,\}" engines/rescript-wasm/lib/; then |
141 | | - echo "::warning::Large integer constants found - verify i31 bounds" |
142 | | - fi |
143 | | - echo "Integer check complete" |
144 | | -
|
145 | | - - name: Security audit - resource leaks |
146 | | - run: | |
147 | | - echo "=== Checking for potential resource leaks ===" |
148 | | - # Check for file handles that might not be closed |
149 | | - FILE_OPENS=$(grep -rn "open_in\|open_out\|In_channel.create\|Out_channel.create" engines/rescript-wasm/lib/ | wc -l) |
150 | | - FILE_CLOSES=$(grep -rn "close_in\|close_out\|In_channel.close\|Out_channel.close\|with_open" engines/rescript-wasm/lib/ | wc -l) |
151 | | - echo "File opens: $FILE_OPENS, File closes: $FILE_CLOSES" |
152 | | - if [ "$FILE_OPENS" -gt "$FILE_CLOSES" ]; then |
153 | | - echo "::warning::Potential resource leak - more opens than closes" |
154 | | - fi |
155 | | - echo "Resource check complete" |
156 | | -
|
157 | | - - name: Security audit - exception handling |
158 | | - run: | |
159 | | - echo "=== Checking exception handling ===" |
160 | | - # Check for bare exception handlers |
161 | | - if grep -rn "try.*with.*_\s*->" engines/rescript-wasm/lib/ | grep -v "failwith\|raise\|error"; then |
162 | | - echo "::warning::Found catch-all exception handlers - may hide errors" |
163 | | - fi |
164 | | - echo "Exception check complete" |
165 | | -
|
166 | | - # Dependency vulnerability scanning |
167 | | - dependency-scan: |
168 | | - name: Dependency Vulnerability Scan |
169 | | - runs-on: ubuntu-latest |
170 | | - permissions: |
171 | | - contents: read |
172 | | - |
173 | | - steps: |
174 | | - - name: Checkout repository |
175 | | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
176 | | - |
177 | | - - name: Set up OCaml |
178 | | - uses: ocaml/setup-ocaml@7c185f622998a008ba1b296d2d7c64e235629c23 # v3.6.1 |
179 | | - with: |
180 | | - ocaml-compiler: "4.14.x" |
181 | | - |
182 | | - - name: List dependencies |
183 | | - run: | |
184 | | - echo "=== OCaml Dependencies ===" |
185 | | - if [ -f engines/rescript-wasm/dune-project ]; then |
186 | | - echo "Dune project dependencies:" |
187 | | - cat engines/rescript-wasm/dune-project |
188 | | - fi |
189 | | - echo "" |
190 | | - echo "=== Installed packages ===" |
191 | | - opam list --installed 2>/dev/null || true |
192 | | -
|
193 | | - - name: Check for known vulnerabilities |
194 | | - run: | |
195 | | - echo "=== Vulnerability Check ===" |
196 | | - # Note: opam doesn't have built-in vulnerability scanning |
197 | | - # This is a placeholder for future integration with security DBs |
198 | | - echo "Dependency check complete (advisory: no known issues)" |
0 commit comments