漏洞参考
Security Scanner MCP 检测的所有漏洞类型的完整参考。
1.2.0 检测语义
JavaScript / TypeScript 的 injection、XSS、crypto、auth、path 检测是 AST 感知的。
- 检测函数参数 taint 到 SQL、MongoDB、command、file-system sink 的流。
- 检测
req.body.file→f→normalized→fs.readFile这样的多跳变量流。 - 检测
res.setHeader('Access-Control-Allow-Origin', '*')CORS 通配符。 - 检测多跳 taint 导致的明文密码存储。
innerHTML的静态字面量 HTML 不作为 XSS 报告,只报告动态值。
OWASP Top 10:2021 映射
A01:2021 - 破损访问控制
我们检测的内容:
- 缺少授权检查
- 不安全的直接对象引用
- 路径穿越漏洞
示例:
// 易受攻击
app.get('/user/:id/data', (req, res) => {
const data = getUserData(req.params.id); // 无身份验证检查
res.json(data);
});
A02:2021 - 密码学故障
我们检测的内容:
- 弱哈希算法(MD5、SHA1)
- 硬编码的加密密钥
- 不安全的随机数生成
- 缺少 SSL/TLS
- 易受攻击的 TLS 版本
示例:
// 易受攻击
const hash = crypto.createHash('md5');
const key = "hardcoded_key_123";
A03:2021 - 注入
我们检测的内容:
- SQL 注入
- NoSQL 注入
- 命令注入
- LDAP 注入
- 表达式语言注入
示例:
// SQL 注入
const query = `SELECT * FROM users WHERE id = ${userId}`;
// 命令注入
exec(`ping ${userInput}`);
// NoSQL 注入
db.users.find({ username: req.body.username });
A04:2021 - 不安全的设计
我们检测的内容:
- 缺少安全控制
- 不充分的输入验证
- 业务逻辑缺陷
A05:2021 - 安全配置错误
我们检测的内容:
- 默认凭证
- 不必要的功能启用
- 不适当的错误处理
- 缺少安全头
- IaC 配置错误
示例:
// 详细错误消息
app.use((err, req, res, next) => {
res.status(500).json({ error: err.stack }); // 泄露内部信息
});
A06:2021 - 易受攻击和过时的组件
我们检测的内容:
- 依赖项中的已知 CVE
- 过时的包
- 易受攻击的框架
检测方法:
- npm audit 集成
- CVE 数据库查询
- 版本检查
A07:2021 - 识别和身份验证故障
我们检测的内容:
- 硬编码凭证
- 弱密码策略
- 不安全的会话管理
- 缺少 MFA
- JWT 配置错误
示例:
// 硬编码凭证
const dbPassword = "admin123";
// 弱 JWT
jwt.sign(payload, 'weak_secret', { algorithm: 'none' });
// 不安全的 Cookie
res.cookie('session', token); // 缺少 httpOnly、secure 标志
A08:2021 - 软件和数据完整性故障
我们检测的内容:
- 缺少完整性检查
- 不安全的反序列化
- 未验证的更新
示例:
# 不安全的反序列化
import pickle
data = pickle.loads(user_input)
A09:2021 - 安全日志和监控故障
我们检测的内容:
- 缺少审计日志
- 监控不足
- 日志注入
A10:2021 - 服务器端请求伪造(SSRF)
我们检测的内容:
- 未验证的 URL
- 内部网络访问
- 云元数据访问
示例:
// SSRF
const url = req.query.url;
axios.get(url); // 无验证
CWE 映射
CWE-78:OS 命令注入
// 易受攻击
child_process.exec(`git clone ${repo_url}`);
// 安全
child_process.execFile('git', ['clone', repo_url]);
CWE-79:跨站脚本(XSS)
// 易受攻击
element.innerHTML = userInput;
// 安全
element.textContent = userInput;
CWE-89:SQL 注入
// 易受攻击
db.query(`SELECT * FROM users WHERE id = ${id}`);
// 安全
db.query('SELECT * FROM users WHERE id = ?', [id]);
CWE-200:信息泄露
// 易受攻击
console.log(error.stack);
res.json({ error: error.message, stack: error.stack });
// 安全
logger.error(error);
res.json({ error: 'Internal server error' });
CWE-259:硬编码密码
// 易受攻击
const password = "admin123";
// 安全
const password = process.env.DB_PASSWORD;
CWE-327:破损密码学
// 易受攻击
crypto.createHash('md5');
// 安全
crypto.createHash('sha256');
CWE-352:跨站请求伪造(CSRF)
// 易受攻击
app.post('/transfer', (req, res) => {
transfer(req.body.amount);
});
// 安全
app.use(csrf());
app.post('/transfer', csrfProtection, (req, res) => {
transfer(req.body.amount);
});
CWE-434:不受限的上传
// 易受攻击
app.post('/upload', (req, res) => {
const file = req.files.upload;
file.mv(`./uploads/${file.name}`);
});
// 安全
const allowedTypes = ['image/jpeg', 'image/png'];
if (!allowedTypes.includes(file.mimetype)) {
return res.status(400).send('Invalid file type');
}
CWE-502:不受信任数据的反序列化
// 易受攻击
const obj = JSON.parse(userInput);
eval(userInput);
// 安全
const obj = JSON.parse(userInput);
// 在使用前验证 obj 结构
CWE-611:XML 外部实体(XXE)
// 易受攻击
const parser = new xml2js.Parser();
parser.parseString(xmlInput);
// 安全
const parser = new xml2js.Parser({
explicitArray: false,
xmlns: false
});
CWE-798:硬编码凭证
// 易受攻击
const apiKey = "sk_live_1234567890";
// 安全
const apiKey = process.env.API_KEY;