安全修复:1.密码哈希验证 2.移除硬编码凭据 3.JWT强密钥 4.CORS白名单

This commit is contained in:
root
2026-04-19 19:20:12 +08:00
parent d00f41a120
commit 38eef97480
14 changed files with 111 additions and 53 deletions
+6 -2
View File
@@ -2,10 +2,14 @@
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
// JWT 密钥(生产环境应从环境变量读取)
const JWT_SECRET = process.env.JWT_SECRET || 'your-jwt-secret-change-in-production';
// JWT 密钥 - 必须通过环境变量设置,不提供默认值
const JWT_SECRET = process.env.JWT_SECRET;
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || '24h';
if (!JWT_SECRET) {
console.error('⚠️ 警告:未设置 JWT_SECRET 环境变量,请在 .env 文件中配置');
}
/**
* 密码哈希
* @param {string} password - 明文密码