🔒 修复中高危安全漏洞并增强文件安全验证
**关键安全修复:** 1. 修复弱随机数生成器(中危) - 分享码生成从Math.random()改为crypto.randomBytes() - 防止分享链接被预测或暴力猜测 2. 增强文件上传安全验证(中危) - 新增isSafePathSegment()函数验证文件名 - 禁止路径遍历字符(..、/、\、控制字符) - 添加上传路径规范化和安全检查 **功能改进:** - 管理员界面显示用户邮箱验证状态 - 优化用户状态展示(已封禁/未激活/正常) **安全影响:** - 消除分享链接可预测性风险 - 防止文件上传路径遍历攻击 - 提升文件系统访问控制安全性 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const Database = require('better-sqlite3');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
// 创建或连接数据库
|
||||
const db = new Database(path.join(__dirname, 'ftp-manager.db'));
|
||||
@@ -297,9 +298,10 @@ const ShareDB = {
|
||||
// 生成随机分享码
|
||||
generateShareCode(length = 8) {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const bytes = crypto.randomBytes(length);
|
||||
let code = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
code += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
code += chars[bytes[i] % chars.length];
|
||||
}
|
||||
return code;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user