| name | snyk-scan |
| description | Scan code and dependencies for vulnerabilities with Snyk: snyk test, snyk monitor, snyk code test, fix guidance, severity thresholds, CI integration. Trigger: when using Snyk, snyk test, snyk monitor, vulnerability scanning, dependency security, snyk code, SAST scanning, CVE scan |
| version | 1 |
| argument-hint | [test|monitor|code|fix|ignore] [--severity-threshold=high] |
| allowed-tools | ["bash","read","write","grep","glob"] |
Snyk Security Scanning
You are now operating in Snyk vulnerability scanning mode.
Installation and Authentication
npm install -g snyk
brew install snyk-cli
snyk auth
snyk auth $SNYK_TOKEN
export SNYK_TOKEN=your-api-token
snyk whoami
Dependency Vulnerability Scanning
snyk test
snyk test --json
snyk test --sarif
snyk test --sarif-file-output=snyk-results.sarif
snyk test --file=package.json
snyk test --file=pom.xml
snyk test --all-projects
snyk test --severity-threshold=high
snyk test --severity-threshold=critical
snyk test --severity-threshold=low
snyk test --dev=false
snyk container test myapp:latest
snyk container test myapp:latest --file=Dockerfile
Code Security Analysis (SAST)
snyk code test
snyk code test --json
snyk code test --sarif
snyk code test --sarif-file-output=snyk-code-results.sarif
snyk code test ./src
snyk code test --severity-threshold=high
Infrastructure as Code Scanning
snyk iac test ./terraform/
snyk iac test ./k8s/
snyk iac test ./cloudformation/
snyk iac test --severity-threshold=high ./terraform/
snyk iac test --sarif ./terraform/
Continuous Monitoring
snyk monitor
snyk monitor --project-name=myapp-production
snyk monitor --all-projects
snyk container monitor myapp:latest
snyk monitor --org=my-org-slug
Fix and Remediation
snyk fix
snyk fix --dry-run
snyk fix --unmanaged
snyk test --json | jq '.vulnerabilities[] | {id, title, fixedIn}'
npm install lodash@4.17.21
snyk open
Ignore and Exceptions
snyk ignore --id=SNYK-JS-LODASH-567746 \
--reason="No current fix available" \
--expiry=2024-12-31
snyk ignore --id=SNYK-JS-LODASH-567746 --reason="False positive"
snyk ignore --id=SNYK-JS-LODASH-567746 --path="lodash@4.17.15"
cat .snyk
cat > .snyk <<'EOF'
version: v1.25.0
ignore:
SNYK-JS-LODASH-567746:
- lodash@4.17.15:
reason: No fix available yet
expires: '2024-12-31T00:00:00.000Z'
EOF
CI/CD Integration
GitHub Actions
name: Snyk Security Scan
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
snyk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Snyk dependency scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Run Snyk code scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: code test
- name: Upload SARIF to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
GitLab CI
snyk-scan:
image: node:18
script:
- npm install -g snyk
- snyk auth $SNYK_TOKEN
- snyk test --severity-threshold=high
variables:
SNYK_TOKEN: $SNYK_TOKEN
Shell Script for CI
#!/bin/bash
set -euo pipefail
snyk auth "$SNYK_TOKEN"
if ! snyk test --severity-threshold=high --json > snyk-results.json 2>&1; then
echo "Snyk found high severity vulnerabilities:"
cat snyk-results.json | jq '.vulnerabilities[] | select(.severity == "high" or .severity == "critical") | {id, title, severity}'
exit 1
fi
if ! snyk code test --severity-threshold=high; then
echo "Snyk Code found high severity issues"
exit 1
fi
echo "All Snyk scans passed"
Interpreting Results
snyk test --json | jq '.vulnerabilities[] | select(.severity == "critical") | {
id: .id,
title: .title,
packageName: .packageName,
version: .version,
fixedIn: .fixedIn
}'
snyk test --json | jq '
.vulnerabilities |
group_by(.severity) |
map({severity: .[0].severity, count: length}) |
.[]
'
snyk test --json | jq '.vulnerabilities[].identifiers.CVE[]?' 2>/dev/null
snyk test --json | jq '[.vulnerabilities[] | select(.isUpgradable == true)] | length'
Troubleshooting
snyk test -d
snyk --version
snyk config unset api
snyk test --offline