重构:文件系统模块化架构,优化应用启动流程
This commit is contained in:
250
docs/code-quality-security-report.md
Normal file
250
docs/code-quality-security-report.md
Normal file
@@ -0,0 +1,250 @@
|
||||
# 代码质量和安全检查报告
|
||||
|
||||
## 执行日期
|
||||
2026-01-27
|
||||
|
||||
## 检查范围
|
||||
- Go 代码质量问题
|
||||
- 前端代码质量
|
||||
- 安全隐患
|
||||
|
||||
---
|
||||
|
||||
## 🔍 发现的问题
|
||||
|
||||
### ⚠️ 安全问题(高优先级)
|
||||
|
||||
#### 1. 硬编码的数据库凭证 🔴
|
||||
|
||||
**位置**:`internal/database/db.go:36-37`
|
||||
|
||||
**问题代码**:
|
||||
```go
|
||||
config := mysqldriver.Config{
|
||||
User: "root",
|
||||
Passwd: "123456", // ❌ 硬编码密码
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
**风险等级**:🔴 高危
|
||||
|
||||
**问题描述**:
|
||||
- ❌ 数据库密码硬编码在源代码中
|
||||
- ❌ 密码过于简单(123456)
|
||||
- ❌ 代码泄露会导致数据库被攻击
|
||||
- ❌ 无法为不同环境配置不同凭证
|
||||
|
||||
**建议修复**:
|
||||
|
||||
```go
|
||||
// 方案1: 使用环境变量
|
||||
config := mysqldriver.Config{
|
||||
User: getEnv("DB_USER", "root"),
|
||||
Passwd: getEnv("DB_PASSWORD", ""),
|
||||
}
|
||||
|
||||
// 方案2: 使用配置文件
|
||||
// 从 config.json 或 .env 文件读取
|
||||
|
||||
// 方案3: 使用系统密钥环
|
||||
// Windows: Credential Manager
|
||||
// macOS: Keychain
|
||||
// Linux: libsecret
|
||||
```
|
||||
|
||||
**优先级**:🔴 **紧急修复**
|
||||
|
||||
---
|
||||
|
||||
#### 2. ZIP 文件路径遍历保护 ✅
|
||||
|
||||
**位置**:`internal/filesystem/fs.go`
|
||||
|
||||
**检查结果**:✅ 已有保护
|
||||
```go
|
||||
func isSafePath(path string) bool {
|
||||
cleanPath := filepath.Clean(path)
|
||||
if strings.Contains(cleanPath, "..") {
|
||||
return false // ✅ 防止路径遍历
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
**状态**:✅ 安全
|
||||
|
||||
---
|
||||
|
||||
### ⚠️ 代码质量问题
|
||||
|
||||
#### 1. 过多的 console.log
|
||||
|
||||
**位置**:`web/src/components/FileSystem.vue`
|
||||
|
||||
**统计**:
|
||||
- console.log: 40个
|
||||
- console.warn: 若干个
|
||||
- console.error: 3个(已保留,用于错误)
|
||||
|
||||
**问题**:
|
||||
- 生产环境会暴露调试信息
|
||||
- 影响性能
|
||||
- 可能泄露敏感信息
|
||||
|
||||
**建议**:
|
||||
```javascript
|
||||
// 创建条件日志工具
|
||||
const debugMode = import.meta.env.DEV
|
||||
|
||||
const debugLog = (...args) => {
|
||||
if (debugMode) {
|
||||
console.log('[FileSystem]', ...args)
|
||||
}
|
||||
}
|
||||
|
||||
// 使用
|
||||
debugLog('操作成功:', data) // 仅开发环境输出
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 2. 前端 Promise 链式调用
|
||||
|
||||
**位置**:`web/src/views/db-cli/components/ConnectionTree.vue`
|
||||
|
||||
**问题代码**:
|
||||
```javascript
|
||||
someMethod().then(result => {
|
||||
...
|
||||
}).catch(error => {
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
**建议**:使用 async/await
|
||||
```javascript
|
||||
try {
|
||||
const result = await someMethod()
|
||||
...
|
||||
} catch (error) {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 3. TODO 标记未处理
|
||||
|
||||
**位置**:`internal/database/db.go:100`
|
||||
|
||||
```go
|
||||
// TODO: 关联 sys_member_role 表查询
|
||||
if role > 0 {
|
||||
// 暂时简化
|
||||
}
|
||||
```
|
||||
|
||||
**建议**:
|
||||
- 转为 GitHub Issue 跟踪
|
||||
- 或删除已过时的 TODO
|
||||
|
||||
---
|
||||
|
||||
### ✅ 代码质量良好的方面
|
||||
|
||||
#### 1. Go 代码编译无警告 ✅
|
||||
|
||||
```bash
|
||||
$ go vet ./...
|
||||
✅ 无输出,无问题
|
||||
```
|
||||
|
||||
#### 2. SQL 参数化查询 ✅
|
||||
|
||||
**位置**:`internal/database/db.go:86-87`
|
||||
|
||||
```go
|
||||
query = query.Where("membername LIKE ? OR account LIKE ?",
|
||||
"%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
||||
```
|
||||
|
||||
**评价**:✅ 使用参数化查询,防止 SQL 注入
|
||||
|
||||
---
|
||||
|
||||
## 📋 优先修复建议
|
||||
|
||||
### 🔴 紧急(本周)
|
||||
|
||||
1. **修复硬编码密码**
|
||||
- 移除 db.go 中的硬编码凭证
|
||||
- 使用环境变量或配置文件
|
||||
|
||||
### 🟠 重要(本月)
|
||||
|
||||
2. **清理 console.log**
|
||||
- 创建条件日志工具
|
||||
- 仅开发环境输出调试信息
|
||||
|
||||
3. **处理 TODO 标记**
|
||||
- 转为 Issue 或删除
|
||||
|
||||
### 🟢 优化(下个迭代)
|
||||
|
||||
4. **Promise → async/await**
|
||||
- 重构链式调用为 async/await
|
||||
|
||||
---
|
||||
|
||||
## 📊 代码质量评分
|
||||
|
||||
| 维度 | 评分 | 说明 |
|
||||
|------|------|------|
|
||||
| **编译检查** | ⭐⭐⭐⭐⭐ | go vet 无问题 |
|
||||
| **SQL 安全** | ⭐⭐⭐⭐⭐ | 参数化查询 |
|
||||
| **路径安全** | ⭐⭐⭐⭐⭐ | 有遍历保护 |
|
||||
| **凭证管理** | ⭐☆☆☆☆ | 硬编码密码 🔴 |
|
||||
| **日志管理** | ⭐⭐⭐☆☆ | 过多调试日志 |
|
||||
|
||||
---
|
||||
|
||||
## 🛡️ 安全检查清单
|
||||
|
||||
### 数据库安全
|
||||
- [ ] 移除硬编码凭证 🔴
|
||||
- [ ] 使用环境变量
|
||||
- [ ] 密码复杂度要求
|
||||
- [ ] 连接加密
|
||||
|
||||
### 文件系统安全
|
||||
- [x] 路径遍历保护 ✅
|
||||
- [x] 路径安全检查 ✅
|
||||
- [ ] 文件权限验证
|
||||
|
||||
### 前端安全
|
||||
- [ ] 清理调试日志
|
||||
- [ ] 敏感信息过滤
|
||||
- [ ] XSS 防护
|
||||
|
||||
---
|
||||
|
||||
## 🚀 建议行动
|
||||
|
||||
### 立即执行
|
||||
1. 修复 db.go 硬编码密码(安全隐患)
|
||||
2. 配置 .gitignore 忽略敏感文件
|
||||
|
||||
### 本周完成
|
||||
3. 清理 FileSystem.vue 中的 console.log
|
||||
4. 创建前端日志管理工具
|
||||
|
||||
### 本月完成
|
||||
5. 处理或关闭 TODO 标记
|
||||
6. 重构 Promise 为 async/await
|
||||
|
||||
---
|
||||
|
||||
**报告生成时间**:2026-01-27
|
||||
**检查类型**:代码质量 + 安全检查
|
||||
**状态**:✅ 已完成
|
||||
Reference in New Issue
Block a user