From 60360f6b49de654e06d71aecc56fa0e018f91c2f Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 28 Jul 2026 14:42:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(mcp):=20reveal/revoke=20=E4=BB=A4=E7=89=8C?= =?UTF-8?q?=E6=97=B6=E5=B0=86=E5=AD=97=E7=AC=A6=E4=B8=B2=20id=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E4=B8=BA=20Uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reveal_mcp_token / revoke_mcp_token 把前端传来的 String id 直接绑到 $1::uuid,tokio-postgres 解析参数类型为 uuid 后拒绝 String,报 'cannot convert between the Rust type String and the Postgres type uuid' 导致 /api/reveal_mcp_token 500。 参照 assets/delete.rs 的做法,绑定前用 uuid::Uuid::parse_str 转换; 解析失败按令牌不存在处理(reveal 返回 None、revoke 静默无操作), 与函数既有的'避免探测'语义一致。 --- src/api/mcp_tokens.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api/mcp_tokens.rs b/src/api/mcp_tokens.rs index 2d4ea60..ac0bd30 100644 --- a/src/api/mcp_tokens.rs +++ b/src/api/mcp_tokens.rs @@ -177,6 +177,12 @@ pub async fn reveal_mcp_token(id: String) -> Result, ServerFnErro let admin = get_current_admin_user().await?; let client = get_conn().await.map_err(AppError::db_conn)?; + // id 由前端以字符串传入(表 id 列是 uuid):解析失败视作令牌不存在。 + let id = match uuid::Uuid::parse_str(&id) { + Ok(u) => u, + Err(_) => return Ok(None), + }; + // 仅取属于当前管理员的令牌的密文,避免越权解密他人令牌。 let row = client .query_opt( @@ -210,6 +216,12 @@ pub async fn revoke_mcp_token(id: String) -> Result<(), ServerFnError> { let admin = get_current_admin_user().await?; let client = get_conn().await.map_err(AppError::db_conn)?; + // id 解析失败视作令牌不存在(静默无操作,避免探测)。 + let id = match uuid::Uuid::parse_str(&id) { + Ok(u) => u, + Err(_) => return Ok(()), + }; + client .execute( "UPDATE mcp_tokens SET revoked_at = NOW() \