关于 vulnerability-scanning
面向需要检查代码、依赖项和容器的团队的漏洞扫描技能。它介绍命令行扫描工具和 CI/CD 实践,包括在发现高危或严重问题时使构建失败。
主要功能
- 01依赖项漏洞扫描
- 02容器和文件系统扫描
- 03Python 代码分析
- 04GitHub Actions 集成
- 05CI/CD 问题处理策略
适用场景
- 01扫描项目依赖项
- 02检查容器镜像和文件系统
- 03在 CI/CD 中加入安全检查
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ secondsky/ claude-skills --skill vulnerability-scanning安装后在 Claude Code 中输入/vulnerability-scanning确认已加载。
详细介绍
漏洞扫描
自动检测代码、依赖项和容器中的安全漏洞。
依赖项扫描
# npm audit
npm audit --audit-level=high
# Snyk
snyk test --severity-threshold=high
# Safety (Python)
safety check --full-report
容器扫描(Trivy)
# Scan container image
trivy image myapp:latest --severity HIGH,CRITICAL
# Scan filesystem
trivy fs --scanners vuln,secret .
GitHub Actions 集成
name: Security Scan
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: 'fs'
severity: 'CRITICAL,HIGH'
exit-code: '1'
- name: Run Snyk
uses: snyk/actions/node@v3
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: npm audit
run: npm audit --audit-level=high
代码分析(Python 的 Bandit)
bandit -r src/ -ll -ii
Node.js 扫描器
const { execSync } = require('child_process');
function runScan(command) {
try {
return JSON.parse(execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] }).toString());
} catch (err) {
// A tool may be missing, exit non-zero, or print non-JSON output (e.g.
// trivy progress text when not on a TTY). Treat that as "no parseable
// result" rather than crashing the scanner.
console.warn(`Scan command failed or returned non-JSON: ${command}`);
return null;
}
}
function runSecurityScan() {
const results = {
npm: runScan('npm audit --json'),
trivy: runScan('trivy fs --quiet --format json .')
};
if (!results.npm || !results.npm.metadata) {
console.warn('npm audit produced no metadata; skipping npm checks');
} else {
const critical = results.npm.metadata?.vulnerabilities?.critical || 0;
if (critical > 0) {
console.error(`Found ${critical} critical vulnerabilities`);
process.exit(1);
}
}
}
最佳实践
- 在 CI/CD 流水线中集成扫描
- 对高危/严重问题阻止构建
- 扫描依赖项和容器
- 持续跟踪漏洞
- 记录已接受的误报
工具
- Trivy(容器、文件系统)
- Snyk(依赖项、代码)
- npm audit / yarn audit
- Bandit(Python)
- OWASP Dependency-Check
评论
支持 Markdown