Repository navigation
134 lines (113 loc) · 4.35 KB
/
Copy pathsecurity-check.yml
File metadata and controls
134 lines (113 loc) · 4.35 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
name: Security Check
on:
pull_request:
branches: [main, develop]
push:
branches: [main]
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
jobs:
security-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run Clippy with security lints
run: |
cargo clippy --workspace --all-targets --all-features -- \
-D warnings \
-W clippy::unwrap_used \
-W clippy::expect_used \
-W clippy::panic \
-W clippy::unimplemented \
-W clippy::todo \
-W clippy::unreachable
- name: Check for unwrap() in production code
run: |
echo "Checking for unwrap() calls in production code..."
# Exclude test files and examples
if find crates -name "*.rs" -type f \
! -path "*/tests/*" \
! -path "*/examples/*" \
! -name "*test*.rs" \
-exec grep -Hn "\.unwrap()" {} \; | grep -v "^[[:space:]]*//"; then
echo "❌ ERROR: Found unwrap() calls in production code!"
echo "Please use ? operator or proper error handling instead."
exit 1
else
echo "✅ No unwrap() calls found in production code"
fi
- name: Check for expect() in production code
run: |
echo "Checking for expect() calls in production code..."
# Allow expect() but warn about it
if find crates -name "*.rs" -type f \
! -path "*/tests/*" \
! -path "*/examples/*" \
! -name "*test*.rs" \
-exec grep -Hn "\.expect(" {} \; | grep -v "^[[:space:]]*//"; then
echo "⚠️ WARNING: Found expect() calls in production code"
echo "Consider using ? operator for better error propagation"
else
echo "✅ No expect() calls found in production code"
fi
- name: Check for panic! in production code
run: |
echo "Checking for panic!() calls in production code..."
if find crates -name "*.rs" -type f \
! -path "*/tests/*" \
! -path "*/examples/*" \
! -name "*test*.rs" \
-exec grep -Hn "panic!" {} \; | grep -v "^[[:space:]]*//"; then
echo "❌ ERROR: Found panic!() calls in production code!"
echo "Please use Result<> and proper error handling instead."
exit 1
else
echo "✅ No panic!() calls found in production code"
fi
- name: Run cargo audit for security vulnerabilities
run: |
cargo install cargo-audit
cargo audit --deny warnings
- name: Check for unsafe code
run: |
echo "Checking for unsafe blocks in code..."
# Count unsafe blocks
UNSAFE_COUNT=$(find crates -name "*.rs" -type f -exec grep -c "unsafe" {} \; | awk '{s+=$1} END {print s}')
echo "Found $UNSAFE_COUNT unsafe blocks/functions"
if [ "$UNSAFE_COUNT" -gt 0 ]; then
echo "⚠️ WARNING: Found unsafe code blocks"
echo "Please ensure all unsafe code is:"
echo " - Necessary and documented"
echo " - Properly reviewed for safety"
echo " - Has safety comments explaining invariants"
fi
- name: Security summary
if: always()
run: |
echo "=== Security Check Summary ==="
echo "✅ Clippy security lints passed"
echo "✅ Production code free of unwrap()"
echo "✅ Production code free of panic!()"
echo "✅ Dependency audit passed"
echo "✅ Unsafe code reviewed (if any)"