本次更新修复了安全测试中发现的所有严重问题,大幅提升系统安全性。 ## 修复的安全问题 ### 1. CORS跨域配置漏洞 ⚠️ 严重 **问题**: 默认允许所有域名访问(ALLOWED_ORIGINS=*) **修复**: - 默认值改为空数组,生产环境必须明确配置域名白名单 - 未配置时拒绝所有跨域请求(生产环境) - 开发环境仅允许localhost访问 ### 2. XSS跨站脚本攻击 ⚠️ 严重 **问题**: 用户输入未过滤,可注入恶意脚本 **修复**: - 添加XSS过滤中间件,自动转义所有POST/PUT请求的用户输入 - 过滤 <, >, ', " 等危险字符 - 递归处理嵌套对象和数组 ### 3. 缺少安全响应头 ⚠️ 重要 **问题**: 缺少X-Frame-Options等安全响应头 **修复**: - X-Frame-Options: SAMEORIGIN (防止点击劫持) - X-Content-Type-Options: nosniff (防止MIME嗅探) - X-XSS-Protection: 1; mode=block - Strict-Transport-Security (HTTPS环境) - Content-Security-Policy (内容安全策略) - 隐藏X-Powered-By和Server版本信息 ### 4. 敏感文件暴露风险 ⚠️ 严重 **问题**: .env、.git等敏感文件可能被访问 **修复**: - Nginx配置禁止访问以.开头的隐藏文件 - 禁止访问.env、.git、.config、.key、.pem等敏感文件 - 更新.gitignore,防止敏感文件提交到代码仓库 - 添加证书、密钥等文件类型到忽略列表 ## 代码改动 ### backend/server.js - 修改CORS默认配置,移除危险的 * 通配符 - 添加安全响应头中间件 - 添加XSS过滤中间件(sanitizeInput函数) - 生产环境强制检查ALLOWED_ORIGINS配置 ### nginx/nginx.conf - 添加安全响应头配置 - 禁止访问隐藏文件和敏感文件的location规则 - 隐藏Nginx版本号(server_tokens off) ### .gitignore - 添加敏感配置文件保护(.env.local, config.json等) - 添加证书和密钥文件类型(.key, .pem, .crt等) ### deploy.sh - 修改默认配置,移除ALLOWED_ORIGINS=* - 添加安全警告提示 ## 部署说明 ⚠️ **重要**: 更新后必须配置ALLOWED_ORIGINS环境变量! ### 手动部署 编辑 `backend/.env` 文件: ```bash ALLOWED_ORIGINS=https://cs.workyai.cn NODE_ENV=production ``` ### 使用install.sh部署 脚本会自动根据域名配置ALLOWED_ORIGINS ## 测试结果 修复前安全评分: 57.6% (14个安全问题) 修复后预期评分: 90%+ (预计解决12+个问题) ## 兼容性 - ✅ 向后兼容,不影响现有功能 - ✅ 开发环境自动允许localhost访问 - ⚠️ 生产环境必须配置ALLOWED_ORIGINS(否则无法访问) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
83 lines
848 B
Plaintext
83 lines
848 B
Plaintext
# 依赖
|
|
node_modules/
|
|
__pycache__/
|
|
*.pyc
|
|
*.pyo
|
|
|
|
# 数据库
|
|
*.db
|
|
*.db-journal
|
|
*.sqlite
|
|
*.sqlite3
|
|
|
|
# 临时文件
|
|
backend/uploads/
|
|
storage/ # 本地存储数据
|
|
*.log
|
|
.DS_Store
|
|
Thumbs.db
|
|
|
|
# 环境配置
|
|
.env
|
|
.env.local
|
|
.env.*.local
|
|
!backend/.env.example
|
|
config.json
|
|
config.*.json
|
|
!**/config.example.json
|
|
|
|
# 敏感配置文件
|
|
*.key
|
|
*.pem
|
|
*.crt
|
|
*.cer
|
|
*.p12
|
|
*.pfx
|
|
secrets.json
|
|
credentials.json
|
|
|
|
# SSL证书
|
|
certbot/
|
|
|
|
# IDE
|
|
.vscode/
|
|
.idea/
|
|
*.swp
|
|
*.swo
|
|
*~
|
|
|
|
# 上传工具构建产物
|
|
upload-tool/dist/
|
|
upload-tool/build/
|
|
upload-tool/__pycache__/
|
|
upload-tool/config.json
|
|
upload-tool/*.spec
|
|
|
|
# 备份文件
|
|
*.bak
|
|
*.backup
|
|
*.old
|
|
|
|
# 操作系统
|
|
.DS_Store
|
|
.Spotlight-V100
|
|
.Trashes
|
|
ehthumbs.db
|
|
Desktop.ini
|
|
|
|
# 压缩文件
|
|
*.zip
|
|
*.tar
|
|
*.gz
|
|
*.rar
|
|
*.7z
|
|
|
|
# npm/yarn
|
|
npm-debug.log*
|
|
yarn-debug.log*
|
|
yarn-error.log*
|
|
package-lock.json.bak
|
|
|
|
# Claude配置
|
|
.claude/
|