fix(saas): 安全修复 — IDOR防护、SSRF防护、JWT密钥强制、错误信息脱敏、CORS配置化
- account: admin 权限守卫 (list_accounts/get_account/update_status/list_logs) - relay: SSRF 防护 (禁止内网地址、限制 http scheme、30s 超时) - config: 生产环境强制 ZCLAW_SAAS_JWT_SECRET 环境变量 - error: 500 错误不再泄露内部细节给客户端 - main: CORS 支持配置白名单 origins - 全部 21 个测试通过 (7 unit + 14 integration)
This commit is contained in:
@@ -107,9 +107,18 @@ impl SaasError {
|
||||
impl IntoResponse for SaasError {
|
||||
fn into_response(self) -> Response {
|
||||
let status = self.status_code();
|
||||
let (error_code, message) = match &self {
|
||||
// 500 错误不泄露内部细节给客户端
|
||||
Self::Database(_) | Self::Internal(_) | Self::Io(_)
|
||||
| Self::Jwt(_) | Self::Config(_) => {
|
||||
tracing::error!("内部错误 [{}]: {}", self.error_code(), self);
|
||||
(self.error_code().to_string(), "服务内部错误".to_string())
|
||||
}
|
||||
_ => (self.error_code().to_string(), self.to_string()),
|
||||
};
|
||||
let body = json!({
|
||||
"error": self.error_code(),
|
||||
"message": self.to_string(),
|
||||
"error": error_code,
|
||||
"message": message,
|
||||
});
|
||||
(status, axum::Json(body)).into_response()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user