dependency-scanning
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDependency Scanning
依赖项扫描
Identify vulnerabilities in third-party dependencies and libraries.
识别第三方依赖项和库中的漏洞。
When to Use This Skill
何时使用该技能
Use this skill when:
- Managing third-party dependencies
- Implementing software composition analysis
- Meeting compliance requirements
- Securing the software supply chain
- Automating vulnerability detection
在以下场景使用该技能:
- 管理第三方依赖项
- 实施软件成分分析
- 满足合规要求
- 保障软件供应链安全
- 自动化漏洞检测
Prerequisites
前置条件
- Package manifest files (package.json, requirements.txt, etc.)
- CI/CD pipeline access
- Dependency scanning tool
- 包清单文件(package.json、requirements.txt等)
- CI/CD流水线访问权限
- 依赖项扫描工具
Tool Comparison
工具对比
| Tool | Type | Languages | Best For |
|---|---|---|---|
| Snyk | Commercial/Free | Many | Comprehensive SCA |
| Dependabot | Free (GitHub) | Many | Automated PRs |
| OWASP Dep-Check | OSS | Many | Free scanning |
| npm audit | Built-in | Node.js | Quick checks |
| pip-audit | OSS | Python | Python projects |
| Trivy | OSS | Many | Container deps |
| 工具 | 类型 | 支持语言 | 最佳适用场景 |
|---|---|---|---|
| Snyk | 商业版/免费版 | 多种 | 全面的软件成分分析(SCA) |
| Dependabot | 免费(GitHub) | 多种 | 自动创建PR |
| OWASP Dep-Check | 开源软件(OSS) | 多种 | 免费扫描 |
| npm audit | 内置工具 | Node.js | 快速检查 |
| pip-audit | 开源软件(OSS) | Python | Python项目 |
| Trivy | 开源软件(OSS) | 多种 | 容器依赖项扫描 |
Snyk
Snyk
CLI Usage
CLI使用方法
bash
undefinedbash
undefinedInstall
Install
npm install -g snyk
npm install -g snyk
Authenticate
Authenticate
snyk auth
snyk auth
Test project
Test project
snyk test
snyk test
Monitor project (track over time)
Monitor project (track over time)
snyk monitor
snyk monitor
Test specific manifest
Test specific manifest
snyk test --file=package.json
snyk test --file=requirements.txt
snyk test --file=package.json
snyk test --file=requirements.txt
Output formats
Output formats
snyk test --json > snyk-results.json
snyk test --sarif > snyk-results.sarif
snyk test --json > snyk-results.json
snyk test --sarif > snyk-results.sarif
Fix vulnerabilities
Fix vulnerabilities
snyk fix
snyk fix
Ignore vulnerability
Ignore vulnerability
snyk ignore --id=SNYK-JS-LODASH-567746 --expiry=2024-12-31 --reason="No exploit path"
undefinedsnyk ignore --id=SNYK-JS-LODASH-567746 --expiry=2024-12-31 --reason="No exploit path"
undefinedCI Integration
CI集成
yaml
undefinedyaml
undefined.github/workflows/snyk.yml
.github/workflows/snyk.yml
name: Snyk Security
on:
push:
branches: [main]
pull_request:
jobs:
snyk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Upload results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarifundefinedname: Snyk Security
on:
push:
branches: [main]
pull_request:
jobs:
snyk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Upload results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarifundefinedPolicy File
策略文件
yaml
undefinedyaml
undefined.snyk
.snyk
version: v1.25.0
ignore:
SNYK-JS-LODASH-567746:
- '*':
reason: No user input reaches this function
expires: 2024-12-31
created: 2024-01-15
'snyk:lic:npm:gpl-3.0':
- '*':
reason: Internal use only
patch: {}
undefinedversion: v1.25.0
ignore:
SNYK-JS-LODASH-567746:
- '*':
reason: No user input reaches this function
expires: 2024-12-31
created: 2024-01-15
'snyk:lic:npm:gpl-3.0':
- '*':
reason: Internal use only
patch: {}
undefinedGitHub Dependabot
GitHub Dependabot
Configuration
配置
yaml
undefinedyaml
undefined.github/dependabot.yml
.github/dependabot.yml
version: 2
updates:
JavaScript/Node.js
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 10
reviewers:
- "security-team" labels:
- "dependencies"
- "security" ignore:
- dependency-name: "aws-sdk"
update-types: ["version-update:semver-major"]
groups:
development-dependencies:
dependency-type: "development"
update-types:
- "minor"
- "patch"
Python
- package-ecosystem: "pip" directory: "/" schedule: interval: "daily"
Docker
- package-ecosystem: "docker" directory: "/" schedule: interval: "weekly"
GitHub Actions
- package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly"
undefinedversion: 2
updates:
JavaScript/Node.js
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 10
reviewers:
- "security-team" labels:
- "dependencies"
- "security" ignore:
- dependency-name: "aws-sdk"
update-types: ["version-update:semver-major"]
groups:
development-dependencies:
dependency-type: "development"
update-types:
- "minor"
- "patch"
Python
- package-ecosystem: "pip" directory: "/" schedule: interval: "daily"
Docker
- package-ecosystem: "docker" directory: "/" schedule: interval: "weekly"
GitHub Actions
- package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly"
undefinedSecurity Alerts
安全警报
yaml
undefinedyaml
undefinedAutomated security updates
Automated security updates
Enable in repository Settings > Security > Dependabot
Enable in repository Settings > Security > Dependabot
Dependabot will automatically:
Dependabot will automatically:
- Create PRs for vulnerable dependencies
- Create PRs for vulnerable dependencies
- Update to patched versions
- Update to patched versions
- Provide CVE details in PR description
- Provide CVE details in PR description
undefinedundefinedOWASP Dependency-Check
OWASP Dependency-Check
Installation
安装
bash
undefinedbash
undefinedDownload
Download
wget https://github.com/jeremylong/DependencyCheck/releases/download/v9.0.0/dependency-check-9.0.0-release.zip
unzip dependency-check-9.0.0-release.zip
wget https://github.com/jeremylong/DependencyCheck/releases/download/v9.0.0/dependency-check-9.0.0-release.zip
unzip dependency-check-9.0.0-release.zip
Or via Homebrew
Or via Homebrew
brew install dependency-check
undefinedbrew install dependency-check
undefinedUsage
使用方法
bash
undefinedbash
undefinedScan project
Scan project
dependency-check --project "MyProject"
--scan /path/to/project
--out /path/to/reports
--format HTML
--format JSON
--scan /path/to/project
--out /path/to/reports
--format HTML
--format JSON
dependency-check --project "MyProject"
--scan /path/to/project
--out /path/to/reports
--format HTML
--format JSON
--scan /path/to/project
--out /path/to/reports
--format HTML
--format JSON
With specific analyzers
With specific analyzers
dependency-check --project "MyProject"
--scan .
--enableExperimental
--disableRetireJS
--scan .
--enableExperimental
--disableRetireJS
dependency-check --project "MyProject"
--scan .
--enableExperimental
--disableRetireJS
--scan .
--enableExperimental
--disableRetireJS
CI configuration
CI configuration
dependency-check --project "MyProject"
--scan .
--format JSON
--failOnCVSS 7
--suppression suppression.xml
--scan .
--format JSON
--failOnCVSS 7
--suppression suppression.xml
undefineddependency-check --project "MyProject"
--scan .
--format JSON
--failOnCVSS 7
--suppression suppression.xml
--scan .
--format JSON
--failOnCVSS 7
--suppression suppression.xml
undefinedSuppression File
抑制文件
xml
<!-- suppression.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress>
<notes>False positive - not using vulnerable function</notes>
<packageUrl regex="true">^pkg:npm/lodash@.*$</packageUrl>
<cve>CVE-2021-23337</cve>
</suppress>
<suppress until="2024-12-31">
<notes>Risk accepted - mitigated by WAF</notes>
<cpe>cpe:/a:apache:struts:2.5.0</cpe>
<vulnerabilityName>CVE-2023-12345</vulnerabilityName>
</suppress>
</suppressions>xml
<!-- suppression.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress>
<notes>False positive - not using vulnerable function</notes>
<packageUrl regex="true">^pkg:npm/lodash@.*$</packageUrl>
<cve>CVE-2021-23337</cve>
</suppress>
<suppress until="2024-12-31">
<notes>Risk accepted - mitigated by WAF</notes>
<cpe>cpe:/a:apache:struts:2.5.0</cpe>
<vulnerabilityName>CVE-2023-12345</vulnerabilityName>
</suppress>
</suppressions>Maven Integration
Maven集成
xml
<!-- pom.xml -->
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>9.0.0</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<suppressionFiles>
<suppressionFile>suppression.xml</suppressionFile>
</suppressionFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>xml
<!-- pom.xml -->
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>9.0.0</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<suppressionFiles>
<suppressionFile>suppression.xml</suppressionFile>
</suppressionFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>Language-Specific Tools
特定语言工具
Node.js (npm audit)
Node.js (npm audit)
bash
undefinedbash
undefinedRun audit
Run audit
npm audit
npm audit
JSON output
JSON output
npm audit --json
npm audit --json
Fix automatically
Fix automatically
npm audit fix
npm audit fix
Fix with breaking changes
Fix with breaking changes
npm audit fix --force
npm audit fix --force
Production only
Production only
npm audit --production
undefinednpm audit --production
undefinedPython (pip-audit)
Python (pip-audit)
bash
undefinedbash
undefinedInstall
Install
pip install pip-audit
pip install pip-audit
Scan installed packages
Scan installed packages
pip-audit
pip-audit
Scan requirements file
Scan requirements file
pip-audit -r requirements.txt
pip-audit -r requirements.txt
Output formats
Output formats
pip-audit --format json
pip-audit --format cyclonedx-json
pip-audit --format json
pip-audit --format cyclonedx-json
Fix vulnerabilities
Fix vulnerabilities
pip-audit --fix
undefinedpip-audit --fix
undefinedGo (govulncheck)
Go (govulncheck)
bash
undefinedbash
undefinedInstall
Install
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
Scan project
Scan project
govulncheck ./...
govulncheck ./...
JSON output
JSON output
govulncheck -json ./...
undefinedgovulncheck -json ./...
undefinedRuby (bundler-audit)
Ruby (bundler-audit)
bash
undefinedbash
undefinedInstall
Install
gem install bundler-audit
gem install bundler-audit
Update database
Update database
bundle-audit update
bundle-audit update
Run audit
Run audit
bundle-audit check
bundle-audit check
Output format
Output format
bundle-audit check --format json
undefinedbundle-audit check --format json
undefinedSBOM Generation
SBOM生成
CycloneDX
CycloneDX
bash
undefinedbash
undefinedNode.js
Node.js
npx @cyclonedx/cyclonedx-npm --output-file sbom.json
npx @cyclonedx/cyclonedx-npm --output-file sbom.json
Python
Python
pip install cyclonedx-bom
cyclonedx-py -o sbom.json
pip install cyclonedx-bom
cyclonedx-py -o sbom.json
Go
Go
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
cyclonedx-gomod mod -json > sbom.json
undefinedgo install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
cyclonedx-gomod mod -json > sbom.json
undefinedSyft
Syft
bash
undefinedbash
undefinedInstall
Install
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s
Generate SBOM
Generate SBOM
syft dir:/path/to/project -o cyclonedx-json > sbom.json
syft dir:/path/to/project -o spdx-json > sbom-spdx.json
syft dir:/path/to/project -o cyclonedx-json > sbom.json
syft dir:/path/to/project -o spdx-json > sbom-spdx.json
From container
From container
syft myimage:latest -o cyclonedx-json > sbom.json
undefinedsyft myimage:latest -o cyclonedx-json > sbom.json
undefinedCI/CD Pipeline
CI/CD流水线
yaml
undefinedyaml
undefinedComprehensive dependency scanning
Comprehensive dependency scanning
name: Dependency Security
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 8 * * *'
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: npm audit
run: npm audit --audit-level=high
- name: Snyk scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Generate SBOM
run: npx @cyclonedx/cyclonedx-npm --output-file sbom.json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.jsonundefinedname: Dependency Security
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 8 * * *'
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: npm audit
run: npm audit --audit-level=high
- name: Snyk scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: Generate SBOM
run: npx @cyclonedx/cyclonedx-npm --output-file sbom.json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.jsonundefinedCommon Issues
常见问题
Issue: Too Many Alerts
问题:警报数量过多
Problem: Overwhelmed by vulnerability count
Solution: Prioritize by exploitability, filter by severity
问题描述:被大量漏洞警报淹没
解决方案:根据可利用性优先处理,按严重程度过滤
Issue: No Fix Available
问题:无可用修复方案
Problem: Vulnerable dependency has no patch
Solution: Consider alternatives, implement compensating controls
问题描述:存在漏洞的依赖项暂无补丁
解决方案:考虑替代方案,实施补偿控制措施
Issue: Breaking Updates
问题:更新导致功能中断
Problem: Security fix breaks functionality
Solution: Review changelogs, test thoroughly, use lockfiles
问题描述:安全修复破坏了现有功能
解决方案:查看变更日志,全面测试,使用锁定文件
Best Practices
最佳实践
- Scan on every build
- Use lockfiles for reproducibility
- Set severity thresholds
- Generate and track SBOMs
- Document exceptions properly
- Update dependencies regularly
- Monitor for new vulnerabilities
- Automate PR creation for updates
- 每次构建时都进行扫描
- 使用锁定文件确保可复现性
- 设置严重程度阈值
- 生成并跟踪SBOM
- 妥善记录例外情况
- 定期更新依赖项
- 监控新出现的漏洞
- 自动创建更新PR
Related Skills
相关技能
- sast-scanning - Code vulnerabilities
- container-scanning - Container dependencies
- github-actions - CI integration
- sast-scanning - 代码漏洞扫描
- container-scanning - 容器依赖项扫描
- github-actions - CI集成