Loading...
Loading...
Security vulnerability scanning using Trivy for ecommerce project. Scans dependencies, container images, and IaC. Blocks CRITICAL and HIGH severity. Triggers on "trivy", "vulnerability scan", "security scan", "container scan", "cve", "dependency scan", "npm audit", "docker scan", "security check". PROACTIVE: MUST invoke before committing code with new dependencies.
npx skill4agent add lorenzogirardi/ai-ecom-demo trivy| Scan Type | Command | When |
|---|---|---|
| Dependencies | | package.json changes |
| Container | | Dockerfile changes |
| IaC | | Terraform changes |
| Trigger | Action |
|---|---|
| Scan filesystem |
| Scan filesystem |
| Scan config + image |
| Scan IaC config |
| Before commit with deps | MANDATORY scan |
# Most common - scan Node.js dependencies
trivy fs \
--severity CRITICAL,HIGH \
--exit-code 1 \
--ignore-unfixed \
--format table \
.# Build image first
docker build -t local-scan:latest .
# Scan the image
trivy image \
--severity CRITICAL,HIGH \
--exit-code 1 \
--ignore-unfixed \
local-scan:latest# Scan Terraform files
trivy config \
--severity CRITICAL,HIGH \
--exit-code 1 \
infra/terraform/| Severity | Action | Commit Allowed |
|---|---|---|
| CRITICAL | BLOCK - Fix immediately | NO |
| HIGH | BLOCK - Fix or upgrade | NO |
| MEDIUM | WARN - Plan remediation | YES |
| LOW | INFO - Document | YES |
# Check which version fixes the CVE
npm audit
# Upgrade specific package
npm install package@latest
# Or use npm audit fix
npm audit fix# Show fixed versions in JSON
trivy fs --severity CRITICAL,HIGH --format json . | \
jq '.Results[].Vulnerabilities[] | {pkg: .PkgName, installed: .InstalledVersion, fixed: .FixedVersion}'// package.json
{
"overrides": {
"vulnerable-package": "^X.Y.Z"
}
}.trivyignore# CVE-2023-XXXXX: Not exploitable - we don't use affected feature
CVE-2023-XXXXXcd apps/backend
trivy fs --severity CRITICAL,HIGH --exit-code 1 .cd apps/frontend
trivy fs --severity CRITICAL,HIGH --exit-code 1 .# Build all images
docker-compose -f docker-compose.full.yml build
# Scan each
trivy image ecommerce-demo-backend:latest
trivy image ecommerce-demo-frontend:latesttrivy config --severity CRITICAL,HIGH infra/terraform/.github/workflows/backend-ci.yml- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: 'apps/backend'
format: 'json'
output: 'security/reports/trivy-backend-${{ github.sha }}.json'security/reports/trivy fs --format json --output report.json .Analyze report.json for contextual CVE prioritization.
For each CVE:
- Search codebase for usage of affected library
- Evaluate if attack vector is exposed
- Provide remediation prioritybrew install trivytrivy fs --severity CRITICAL,HIGH --exit-code 1 ..trivyignore| Issue | Solution |
|---|---|
| |
| Slow scan | Use |
| False positive | Add to |
| Transitive dependency | Use |
| Old DB | Run |