dependency-audit.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # Audit dependencies for known vulnerabilities
  3. # Usage: ./dependency-audit.sh
  4. set -e
  5. RED='\033[0;31m'
  6. GREEN='\033[0;32m'
  7. YELLOW='\033[1;33m'
  8. NC='\033[0m'
  9. echo "=== Dependency Security Audit ==="
  10. echo ""
  11. # Python
  12. if [ -f "requirements.txt" ] || [ -f "pyproject.toml" ]; then
  13. echo "--- Python Dependencies ---"
  14. if command -v pip-audit &> /dev/null; then
  15. echo "Running pip-audit..."
  16. pip-audit || true
  17. elif command -v safety &> /dev/null; then
  18. echo "Running safety check..."
  19. safety check || true
  20. else
  21. echo -e "${YELLOW}Install pip-audit or safety for Python vulnerability scanning${NC}"
  22. echo " pip install pip-audit"
  23. fi
  24. echo ""
  25. fi
  26. # Node.js
  27. if [ -f "package.json" ]; then
  28. echo "--- Node.js Dependencies ---"
  29. if command -v npm &> /dev/null; then
  30. echo "Running npm audit..."
  31. npm audit --audit-level=moderate || true
  32. fi
  33. echo ""
  34. fi
  35. # Go
  36. if [ -f "go.mod" ]; then
  37. echo "--- Go Dependencies ---"
  38. if command -v govulncheck &> /dev/null; then
  39. echo "Running govulncheck..."
  40. govulncheck ./... || true
  41. else
  42. echo -e "${YELLOW}Install govulncheck for Go vulnerability scanning${NC}"
  43. echo " go install golang.org/x/vuln/cmd/govulncheck@latest"
  44. fi
  45. echo ""
  46. fi
  47. # Rust
  48. if [ -f "Cargo.toml" ]; then
  49. echo "--- Rust Dependencies ---"
  50. if command -v cargo-audit &> /dev/null; then
  51. echo "Running cargo audit..."
  52. cargo audit || true
  53. else
  54. echo -e "${YELLOW}Install cargo-audit for Rust vulnerability scanning${NC}"
  55. echo " cargo install cargo-audit"
  56. fi
  57. echo ""
  58. fi
  59. # Docker
  60. if [ -f "Dockerfile" ]; then
  61. echo "--- Docker Image ---"
  62. if command -v trivy &> /dev/null; then
  63. echo "Running trivy on Dockerfile..."
  64. trivy config Dockerfile || true
  65. else
  66. echo -e "${YELLOW}Install trivy for container vulnerability scanning${NC}"
  67. echo " brew install trivy"
  68. fi
  69. echo ""
  70. fi
  71. echo "=== Audit Complete ==="
  72. echo ""
  73. echo "Recommended actions:"
  74. echo "1. Update vulnerable packages to patched versions"
  75. echo "2. Review advisories for workarounds if updates unavailable"
  76. echo "3. Consider alternative packages for unmaintained dependencies"