|
| 1 | +# Security Testing Guide |
| 2 | + |
| 3 | +This guide explains how to run security scans locally before pushing to CI. |
| 4 | + |
| 5 | +## ClamAV Malware Scan |
| 6 | + |
| 7 | +### Installation |
| 8 | + |
| 9 | +**macOS:** |
| 10 | +```bash |
| 11 | +brew install clamav |
| 12 | +``` |
| 13 | + |
| 14 | +**Ubuntu/Debian:** |
| 15 | +```bash |
| 16 | +sudo apt-get update |
| 17 | +sudo apt-get install clamav clamav-daemon |
| 18 | +``` |
| 19 | + |
| 20 | +### Update Virus Database |
| 21 | + |
| 22 | +```bash |
| 23 | +# Stop the freshclam daemon if running |
| 24 | +sudo systemctl stop clamav-freshclam # Linux |
| 25 | +# or |
| 26 | +brew services stop clamav # macOS |
| 27 | + |
| 28 | +# Update the database |
| 29 | +sudo freshclam |
| 30 | +# or |
| 31 | +freshclam # if running as user |
| 32 | +``` |
| 33 | + |
| 34 | +### Run Scan Locally |
| 35 | + |
| 36 | +```bash |
| 37 | +# Scan the repository (excluding node_modules, .git, dist) |
| 38 | +clamscan -r -i --exclude-dir=node_modules --exclude-dir=.git --exclude-dir=dist . |
| 39 | +``` |
| 40 | + |
| 41 | +**Options:** |
| 42 | +- `-r` : Recursive scan |
| 43 | +- `-i` : Only show infected files |
| 44 | +- `--exclude-dir` : Exclude specific directories |
| 45 | + |
| 46 | +### Expected Output |
| 47 | + |
| 48 | +If no malware is detected: |
| 49 | +``` |
| 50 | +----------- SCAN SUMMARY ----------- |
| 51 | +Known viruses: 8700000 |
| 52 | +Engine version: 1.0.0 |
| 53 | +Scanned directories: X |
| 54 | +Scanned files: XXX |
| 55 | +Infected files: 0 |
| 56 | +Data scanned: XX.XX MB |
| 57 | +Time: XX.XXX sec (X m XXs) |
| 58 | +Start Date: YYYY:MM:DD HH:MM:SS |
| 59 | +End Date: YYYY:MM:DD HH:MM:SS |
| 60 | +``` |
| 61 | + |
| 62 | +## Other Security Scans |
| 63 | + |
| 64 | +### Semgrep |
| 65 | + |
| 66 | +```bash |
| 67 | +# Install |
| 68 | +pip install semgrep |
| 69 | + |
| 70 | +# Run scan |
| 71 | +semgrep scan --config auto . |
| 72 | +``` |
| 73 | + |
| 74 | +### Gitleaks (Secret Detection) |
| 75 | + |
| 76 | +```bash |
| 77 | +# Install |
| 78 | +brew install gitleaks # macOS |
| 79 | +# or download from https://github.com/gitleaks/gitleaks/releases |
| 80 | + |
| 81 | +# Run scan |
| 82 | +gitleaks detect --source . --no-git |
| 83 | +``` |
| 84 | + |
| 85 | +### Dependency Audit |
| 86 | + |
| 87 | +```bash |
| 88 | +# Check for vulnerable dependencies |
| 89 | +npx audit-ci --package-manager yarn --severity high |
| 90 | +``` |
| 91 | + |
| 92 | +### All Tests |
| 93 | + |
| 94 | +```bash |
| 95 | +# Run unit tests with coverage |
| 96 | +yarn test |
| 97 | +yarn coverage |
| 98 | +``` |
| 99 | + |
| 100 | +## Continuous Integration |
| 101 | + |
| 102 | +All these scans run automatically in GitHub Actions on every push: |
| 103 | + |
| 104 | +- **Test** : Unit tests with coverage |
| 105 | +- **Semgrep** : SAST security scanning |
| 106 | +- **CodeQL** : Advanced security analysis |
| 107 | +- **Gitleaks** : Secret detection |
| 108 | +- **Dependency Audit** : npm/yarn vulnerability check |
| 109 | +- **ClamAV** : Malware detection |
| 110 | + |
| 111 | +Check `.github/workflows/ci.yml` for the full CI configuration. |
| 112 | + |
| 113 | +## Troubleshooting |
| 114 | + |
| 115 | +### ClamAV Database Update Fails |
| 116 | + |
| 117 | +If `freshclam` fails with permission errors: |
| 118 | +```bash |
| 119 | +sudo freshclam |
| 120 | +``` |
| 121 | + |
| 122 | +If it fails because the daemon is running: |
| 123 | +```bash |
| 124 | +# Linux |
| 125 | +sudo systemctl stop clamav-freshclam |
| 126 | +sudo freshclam |
| 127 | +sudo systemctl start clamav-freshclam |
| 128 | + |
| 129 | +# macOS |
| 130 | +brew services stop clamav |
| 131 | +freshclam |
| 132 | +brew services start clamav |
| 133 | +``` |
| 134 | + |
| 135 | +### ClamAV Scan Takes Too Long |
| 136 | + |
| 137 | +Use the `-i` flag to only show infected files and speed up output: |
| 138 | +```bash |
| 139 | +clamscan -r -i --exclude-dir=node_modules . |
| 140 | +``` |
| 141 | + |
| 142 | +### False Positives |
| 143 | + |
| 144 | +If ClamAV reports a false positive: |
| 145 | +1. Verify the file is legitimate |
| 146 | +2. Report to ClamAV: https://www.clamav.net/reports/fp |
| 147 | +3. Add to exclusion list if needed |
0 commit comments