关于 owasp-top-10
面向应用安全审查的 Skill,整理 OWASP Top 10:2025 风险与预防实践。内容包括十类风险的速查、示例、扫描命令和故障排查。
主要功能
- 01涵盖 2025 年全部十类风险
- 02提供预防建议和代码示例
- 03列出安全扫描命令
- 04包含风险预防检查清单
- 05提供故障排查与反模式说明
适用场景
- 01审查应用安全风险
- 02检查访问控制与身份验证实践
- 03审计依赖项和注入防护
- 04查找常见安全问题的修复建议
MCP 相关
该 Skill 提及使用 `mcp__documentation__fetch_docs` 并指定技术 `owasp` 来获取完整文档。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ claude-dev-suite/ claude-dev-suite --skill owasp-top-10安装后在 Claude Code 中输入/owasp-top-10确认已加载。
详细介绍
OWASP Top 10:2025
不应使用此 Skill 的情况
- OWASP Top 10:2021 - 2021 版本请使用
owaspskill - 详细的密钥管理 - 请使用
secrets-managementskill - 详细的供应链安全 - 如需深入了解依赖项管理,请使用
supply-chainskill - 许可证合规 - 请使用
license-complianceskill
深入了解:使用
mcp__documentation__fetch_docs,并将技术指定为owasp,获取完整文档。
快速参考
| 排名 | 类别 | 预防措施 |
|---|---|---|
| A01 | 访问控制失效 | 授权检查,默认拒绝 |
| A02 | 安全配置错误 | 加固,安全标头,不使用默认设置 |
| A03 | 供应链失效 | 依赖项审计,锁文件,SBOM |
| A04 | 加密失效 | 强算法,妥善管理密钥 |
| A05 | 注入 | 参数化查询,输入验证 |
| A06 | 不安全设计 | 威胁建模,安全模式 |
| A07 | 身份验证失效 | MFA,速率限制,安全会话 |
| A08 | 完整性失效 | 签名更新,安全反序列化 |
| A09 | 日志记录失效 | 审计日志,告警,监控 |
| A10 | 异常处理 | 优雅处理错误,不泄露信息 |
A01:访问控制失效
// Always verify ownership
if (resource.userId !== currentUser.id) {
throw new ForbiddenException();
}
// Deny by default
const allowed = permissions.includes(requiredPermission);
if (!allowed) throw new ForbiddenException();
// Rate limit sensitive endpoints
app.use('/api/admin/*', adminRateLimiter);
A02:安全配置错误
// Security headers
import helmet from 'helmet';
app.use(helmet());
// Strict CORS
app.use(cors({
origin: ['https://myapp.com'],
credentials: true
}));
// Hide errors in production
if (process.env.NODE_ENV === 'production') {
app.use((err, req, res, next) => {
res.status(500).json({ error: 'Internal error' });
});
}
A03:供应链失效(2025 年新增)
# Audit dependencies
npm audit
pip-audit
mvn dependency-check:check
# Use lockfiles
npm ci # Instead of npm install
# Verify package integrity
npm install --ignore-scripts
npm config set ignore-scripts true
A04:加密失效
// Strong password hashing
import { hash, verify } from 'argon2';
const hashed = await hash(password, { type: argon2id });
// Secure random
import { randomBytes, randomUUID } from 'crypto';
const token = randomBytes(32).toString('hex');
// AES-256-GCM for encryption (not CBC)
A05:注入
// SQL - use parameterized queries
const user = await prisma.user.findUnique({ where: { id } });
await db.query('SELECT * FROM users WHERE id = $1', [id]);
// Command - use execFile, not exec
import { execFile } from 'child_process';
execFile('ls', ['-la', safeArg]);
// XSS - sanitize HTML
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);
A06:不安全设计
关键实践:
- 在设计阶段进行威胁建模
- 使用安全设计模式(故障安全、纵深防御)
- 在用户故事中加入安全要求
- 测试滥用场景
A07:身份验证失效
// Rate limiting
import rateLimit from 'express-rate-limit';
const loginLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 5
});
// Secure cookies
res.cookie('session', token, {
httpOnly: true,
secure: true,
sameSite: 'strict'
});
// Strong passwords (12+ chars, mixed)
A08:完整性失效
// Verify signatures on updates
// Use subresource integrity (SRI)
<script src="lib.js"
integrity="sha384-..."
crossorigin="anonymous">
</script>
// Safe deserialization
// Avoid: JSON.parse(untrusted)
// Use: zod/yup validation
A09:日志记录与告警失效
// Log security events
logger.warn({
event: 'auth_failure',
userId: attemptedId,
ip: req.ip,
timestamp: new Date().toISOString()
});
// Events to log:
// - Login success/failure
// - Password changes
// - Permission denied
// - Rate limit exceeded
A10:异常处理(2025 年新增)
// Graceful error handling
try {
await riskyOperation();
} catch (error) {
logger.error({ error, context });
// Generic response to user
throw new InternalServerException('Operation failed');
}
// Never expose stack traces
// Never expose internal paths
// Never expose SQL/DB errors
安全扫描命令
# Dependencies
npm audit --json
snyk test
# Secrets
gitleaks detect
trufflehog git file://.
# SAST
semgrep --config=p/security-audit .
# Docker
trivy image myimage:latest
检查清单
| 风险 | 预防措施 |
|---|---|
| SQL 注入 | 参数化查询,ORM |
| XSS | 转义输出,CSP 标头 |
| CSRF | CSRF 令牌,SameSite Cookie |
| 身份验证问题 | MFA,速率限制,安全会话 |
| 密钥 | 环境变量,保险库 |
| 供应链 | 审计,锁文件,SBOM |
反模式
| 反模式 | 不良影响 | 正确做法 |
|---|---|---|
| 仅在前端检查权限 | 可绕过客户端检查(A01) | 始终在后端验证 |
| 使用弱加密算法(MD5、DES) | 容易被破解(A04) | 使用 AES-256-GCM、argon2、SHA-256+ |
在 CI/CD 中使用 npm install | 构建结果不确定(A03) | 使用 npm ci 和锁文件 |
| 静默捕获所有异常 | 隐藏安全问题(A10) | 记录错误,妥善处理 |
| 在查询中信任用户输入 | 注入攻击(A05) | 始终使用参数化查询 |
| 没有会话超时 | 会话劫持(A07) | 实施空闲超时和绝对超时 |
快速故障排查
| 问题 | 可能原因 | 解决方案 |
|---|---|---|
| npm audit 显示漏洞 | 依赖项过时(A03) | 运行 npm audit fix 或手动更新 |
| 尝试 5 次后登录始终失败 | 速率限制器过于严格(A07) | 检查速率限制设置 |
| 密钥泄露在 git 历史记录中 | 提交了 .env 文件(A02) | 使用 BFG 清理历史记录并轮换密钥 |
| 数据库查询缓慢或失败 | SQL 注入攻击(A05) | 检查日志,改用参数化查询 |
| 用户可以访问他人的数据 | 缺少授权(A01) | 在所有端点中添加所有权检查 |
| 生产环境中出现堆栈跟踪 | 禁用了异常处理(A10) | 启用生产环境错误处理 |
相关技能
评论
支持 Markdown