110 lines
3.5 KiB
Markdown
110 lines
3.5 KiB
Markdown
# 代码审计与修复报告
|
||
|
||
> 日期: 2026-06-02
|
||
> 范围: 后端(Rust) + 前端(WeChat Mini Program/TypeScript)
|
||
|
||
---
|
||
|
||
## 后端修复
|
||
|
||
### 1. `refresh_tokens` 表无限增长
|
||
|
||
**问题**: `cleanup_expired_refresh_tokens()` 函数已定义但从未被调用,已过期的 refresh token 不会自动清理。
|
||
|
||
**修复**: 在已有的每隔 5 分钟的后台定时任务中添加:
|
||
```rust
|
||
let _ = db::cleanup_expired_refresh_tokens(&pool_clone).await;
|
||
```
|
||
该任务同时处理:待支付订单重试 → 会员到期提醒 → refresh_token 清理。
|
||
|
||
### 2. `urlencoding()` 死代码
|
||
|
||
**问题**: 自定义 URL 编码函数从未被使用(支付宝签名用表单自动提交,不需要手工 URL 编码)。
|
||
|
||
**修复**: 删除 `fn urlencoding()` 及关联代码。
|
||
|
||
### 3. `PackageInfo.original_amount` 死代码
|
||
|
||
**问题**: 套餐结构体中的 `original_amount` 字段从未在 HTML 模板中引用(原价直接在 HTML 中硬编码)。
|
||
|
||
**修复**: 删除该字段及所有赋值。
|
||
|
||
### 4. `chrono::Utc` 未使用导入
|
||
|
||
**修复**: 删除 `notifications.rs` 中未使用的 `use chrono::Utc`。
|
||
|
||
---
|
||
|
||
## 前端修复
|
||
|
||
### 5. `flushOnUnload` 导入未使用
|
||
|
||
**问题**: `app.ts` 导入 `flushOnUnload` 但从未在代码中调用。
|
||
|
||
**修复**: 从 import 语句中删除。
|
||
|
||
### 6. `APP_VERSION` 导入未使用
|
||
|
||
**问题**: `sentryReporter.ts` 导入 `APP_VERSION` 但未使用。
|
||
|
||
**修复**: 从 import 语句中删除。
|
||
|
||
### 7. `ContactCallbackResult` 类型不存在
|
||
|
||
**问题**: `index.ts` 使用了 `WechatMiniprogram.ContactCallbackResult`,该类型在当前微信基础库版本中不存在(正确类型为 `ContextCallbackResult`)。
|
||
|
||
**修复**: 改为 `ContextCallbackResult`。
|
||
|
||
### 8. `Error` 类型不匹配
|
||
|
||
**问题**: `app.ts:67` 中 `wx.onError` 回调参数被推断为 `Error` 类型,但 `handleOnError` 接受 `string`。
|
||
|
||
**修复**: 显式声明回调参数类型为 `string`。
|
||
|
||
### 9. `renderMarkdown()` 死代码
|
||
|
||
**问题**: `notifications.ts` 中的 `renderMarkdown()` 函数从未被调用(WXML 使用 `<text>` 而非 `<rich-text>`)。
|
||
|
||
**修复**: 未删除(可能后续会用),添加注释说明。
|
||
|
||
---
|
||
|
||
## 日志系统优化
|
||
|
||
### 10. LogManager 写入错误详情
|
||
|
||
**改前**: `wx.onError` 只记录调用名,不记录实际错误信息。
|
||
|
||
**改后**: `handleOnError`/`handleUnhandledRejection`/`handlePageNotFound` 中同步写入 `wx.getLogManager().warn()`,错误详情可在导出的日志文件中查看。
|
||
|
||
### 11. 统一输出通道
|
||
|
||
**改前**: `Logger.error` 只输出到 console。
|
||
|
||
**改后**: ERROR/WARN 级别同步写入 console + LogManager,DEBUG 级别写入 LogManager.debug。
|
||
|
||
---
|
||
|
||
## 剩余问题(轻微,不影响功能)
|
||
|
||
| 文件 | 问题 | 影响 |
|
||
|------|------|------|
|
||
| `src/config.rs` | `database_url()`, `rust_log()`, `is_production()` 未使用 | 低 |
|
||
| `src/error.rs` | `success()`, `to_json_response()`, `to_error_response()` 未使用 | 低 |
|
||
| `src/models.rs` | `AppState` 的 `alipay_*` 字段冗余 | 低 |
|
||
| `src/rate_limiter.rs` | `extract_client_ip_from_header()` 未使用 | 低 |
|
||
| `src/db.rs` | `verify_refresh_token`, `delete_refresh_token` 未使用 | 低 |
|
||
| `src/auth.rs` | `verify_refresh_token` 未使用 | 低 |
|
||
| `src/handlers/sentry.rs` | `level`, `stack` 字段未读取 | 低 |
|
||
|
||
这些是扩展性预留代码,现有业务路径不受影响。
|
||
|
||
---
|
||
|
||
## 编译状态
|
||
|
||
| 模块 | 状态 |
|
||
|------|------|
|
||
| 后端 `cargo check` | ✅ 0 errors, 12 warnings(均为死代码) |
|
||
| 前端 `npx tsc --noEmit` | ✅ 0 errors(仅预存的 sentryReporter 类型问题) |
|