-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (112 loc) · 3.76 KB
/
Copy pathsecurity.yml
File metadata and controls
132 lines (112 loc) · 3.76 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
name: Security & Quality
on:
push:
branches: [master]
pull_request:
branches: [master]
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: read
security-events: write
actions: read
jobs:
codeql:
name: CodeQL Analysis
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- uses: actions/checkout@v6
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: javascript-typescript
queries: security-extended
- name: Autobuild
uses: github/codeql-action/autobuild@v4
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
audit:
name: Dependency Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Run npm audit
run: npm audit --audit-level=high || true
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Check for critical vulnerabilities
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
run: |
RESULT=$(npm audit --json 2>/dev/null | node -e "
const data=require('fs').readFileSync('/dev/stdin','utf8');
try {
const audit=JSON.parse(data);
const critical=(audit.metadata?.vulnerabilities?.critical||0);
console.log(critical);
} catch { console.log('0'); }
")
echo "High/Critical vulnerabilities: $RESULT"
if [ "$RESULT" -gt 0 ] 2>/dev/null; then
echo "::error::Found $RESULT high/critical vulnerabilities"
exit 1
fi
eslint-security:
name: ESLint Security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
- name: Install ESLint with security plugin
run: npm install --no-save eslint@8 eslint-plugin-security@1.7.1
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Create security ESLint config
run: |
cat > .eslintrc.security.json << 'ESLINTEOF'
{
"plugins": ["security"],
"extends": ["plugin:security/recommended"],
"env": { "node": true, "es2022": true },
"parserOptions": { "ecmaVersion": 2022 },
"rules": {
"security/detect-eval-with-expression": "error",
"security/detect-non-literal-fs-filename": "warn",
"security/detect-non-literal-require": "warn",
"security/detect-possible-timing-attacks": "warn",
"security/detect-child-process": "warn"
}
}
ESLINTEOF
- name: Run ESLint security scan
run: npx eslint -c .eslintrc.security.json "src/**/*.js" "public/**/*.js" --no-eslintrc --format stylish || true
trivy:
name: Trivy Container Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Build Docker image
run: docker build --build-arg NODE_AUTH_TOKEN="$NODE_AUTH_TOKEN" -t gatecontrol:security-scan .
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'gatecontrol:security-scan'
format: 'table'
exit-code: '1'
severity: 'CRITICAL,HIGH'
ignore-unfixed: true
trivyignores: '.trivyignore'