fix: 隐藏内部错误信息,防止敏感数据泄露

- 移除 ErrorResponse.errmsg 中的 e.to_string() 调用
- 将详细的内部错误信息改为 None,用户看不到内部详情
- 错误详情仍然记录到 JSON 日志,供开发者排查
- 健康检查端点也使用友好的错误信息
- 更新 IMPROVEMENTS.md 标记 1.3 完成

影响范围:
- src/main.rs: login handler (2处)
- src/main.rs: health_check handler (1处)
This commit is contained in:
2026-04-15 11:11:16 +08:00
parent 6b871ca4d6
commit e8990f7771
2 changed files with 8 additions and 5 deletions

View File

@@ -150,7 +150,7 @@ async fn login(
return HttpResponse::InternalServerError().json(ErrorResponse {
error: "用户信息处理失败".to_string(),
errcode: Some(500),
errmsg: Some(e.to_string()),
errmsg: None,
});
}
};
@@ -165,7 +165,7 @@ async fn login(
return HttpResponse::InternalServerError().json(ErrorResponse {
error: "生成身份令牌失败".to_string(),
errcode: Some(500),
errmsg: Some(e.to_string()),
errmsg: None,
});
}
};
@@ -694,7 +694,7 @@ async fn health_check(pool: web::Data<PgPool>) -> impl Responder {
HttpResponse::ServiceUnavailable().json(serde_json::json!({
"status": "unhealthy",
"database": "disconnected",
"error": e.to_string()
"error": "数据库连接失败"
}))
}
}