-
Notifications
You must be signed in to change notification settings - Fork 15
171 lines (162 loc) · 7.22 KB
/
Copy pathci.yml
File metadata and controls
171 lines (162 loc) · 7.22 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
# ──────────────────────────────────────────────────────────
# Code correctness
# ──────────────────────────────────────────────────────────
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run typecheck
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run format:check
# ──────────────────────────────────────────────────────────
# Code-level vulnerability scanning (SAST)
# ──────────────────────────────────────────────────────────
codeql:
name: CodeQL SAST
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
queries: +security-extended,security-and-quality
- uses: github/codeql-action/autobuild@v3
- uses: github/codeql-action/analyze@v3
# ──────────────────────────────────────────────────────────
# Custom static analysis — pi extension attack patterns
# ──────────────────────────────────────────────────────────
semgrep:
name: Semgrep — pi extension audit
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
container:
image: semgrep/semgrep:latest
steps:
- uses: actions/checkout@v4
- name: Run Semgrep with custom rules
run: |
semgrep --config .semgrep/ --error --output semgrep-report.sarif --sarif .
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: semgrep-report.sarif
category: semgrep-pi-audit
if: always()
# ──────────────────────────────────────────────────────────
# Hardcoded secrets detection
# ──────────────────────────────────────────────────────────
gitleaks:
name: Gitleaks — secrets scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_ENABLE_COMMENTS: "true"
# ──────────────────────────────────────────────────────────
# Dependency supply-chain security
# ──────────────────────────────────────────────────────────
deps-review:
name: Dependency review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Check if dependency graph is enabled
run: |
echo "Dependency review requires enabling Dependency graph in repo settings."
echo "Go to: https://github.com/patlux/pi-commandcode-provider/settings/security_analysis"
echo "Enable: Dependency graph"
- uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
allow-licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD
comment-summary-in-pr: always
continue-on-error: true
deps-audit:
name: npm audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm audit --audit-level=moderate
- name: Exit gracefully on audit findings
if: failure()
run: |
echo "::warning::npm audit found vulnerabilities. Review and patch before merging."
# ──────────────────────────────────────────────────────────
# Postinstall script check — prevents install-time malware
# ──────────────────────────────────────────────────────────
check-scripts:
name: Check lifecycle scripts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for malicious lifecycle scripts
run: |
echo "::group::package.json scripts"
node -e "
const pkg = require('./package.json');
const dangerous = ['preinstall','install','postinstall','prepublish','prepare'];
const found = dangerous.filter(s => pkg.scripts && pkg.scripts[s]);
if (found.length) {
found.forEach(s => console.log('WARNING: package.json has "' + s + '":', pkg.scripts[s]));
process.exit(1);
} else {
console.log('No dangerous lifecycle scripts in package.json');
}
"
echo "::endgroup::"
echo "::group::dependency scripts (top-level)"
npm query '.scripts' --all 2>/dev/null | node -e "
const d = require('fs').readFileSync('/dev/stdin','utf8');
if (!d.trim()) { console.log('No dependency scripts found'); process.exit(0); }
let pkgs;
try { pkgs = JSON.parse(d); } catch(e) { console.log('Could not parse npm query output'); process.exit(0); }
if (!Array.isArray(pkgs)) pkgs = Object.values(pkgs);
const withScripts = pkgs.filter(p => p && p.pkgid && p.scripts);
withScripts.forEach(p => {
const dangerous = ['preinstall','install','postinstall','prepublish','prepare'];
const has = Object.keys(p.scripts || {}).filter(s => dangerous.includes(s));
if (has.length) console.log('⚠', p.pkgid, 'has scripts:', Object.keys(p.scripts));
});
if (withScripts.length === 0) console.log('No dependency lifecycle scripts');
" 2>&1 || true
echo "::endgroup::"