forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan-dependencies.sh
More file actions
39 lines (31 loc) · 1.1 KB
/
Copy pathscan-dependencies.sh
File metadata and controls
39 lines (31 loc) · 1.1 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
#!/usr/bin/env bash
set -euo pipefail
# scan-dependencies.sh — Scan project dependencies for known vulnerabilities
# Usage: ./scan-dependencies.sh [--fail-on high|critical]
FAIL_ON="${2:-critical}"
REPORT_DIR="${REPORT_DIR:-/tmp/security-reports}"
mkdir -p "$REPORT_DIR"
REPORT="$REPORT_DIR/dep-scan-$(date +%Y%m%d-%H%M%S).json"
log() { echo "[$(date +%H:%M:%S)] $*"; }
log "Scanning dependencies (fail-on: $FAIL_ON)..."
# Node.js — npm audit
if [[ -f "package.json" ]]; then
log "Running npm audit..."
npm audit --json > "$REPORT_DIR/npm-audit.json" 2>/dev/null || true
fi
# Rust — cargo audit
if [[ -f "contracts/Cargo.toml" ]]; then
log "Running cargo audit..."
cargo audit --json > "$REPORT_DIR/cargo-audit.json" 2>/dev/null || true
fi
# Trivy filesystem scan (covers all ecosystems)
log "Running Trivy filesystem scan..."
trivy fs . \
--severity "$(echo "$FAIL_ON" | tr '[:lower:]' '[:upper:]'),HIGH" \
--format json \
--output "$REPORT" \
--exit-code 1 2>/dev/null || {
log "VULNERABILITIES FOUND — review $REPORT"
exit 1
}
log "No $FAIL_ON vulnerabilities found. Report: $REPORT"