From 74f061cfeb3a6997038288d8ef65eabbb157619b Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 26 Feb 2026 09:39:14 -0800 Subject: [PATCH] =?UTF-8?q?fix(auth-service):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AF=86=E7=A0=81DTO=E7=BC=BA=E5=B0=91class-?= =?UTF-8?q?validator=E8=A3=85=E9=A5=B0=E5=99=A8=E5=AF=BC=E8=87=B4=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=A2=ABValidationPipe=E6=8B=92=E7=BB=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:ValidationPipe配置了whitelist+forbidNonWhitelisted,但DTO类的属性 没有任何class-validator装饰器,导致所有请求体属性被当作非白名单属性直接 返回Bad Request,请求根本未到达业务逻辑层。 修复:为SetTradePasswordDto、ChangeTradePasswordDto、VerifyTradePasswordDto 添加@IsString()和@IsNotEmpty()装饰器。 Co-Authored-By: Claude Opus 4.6 --- .../api/controllers/trade-password.controller.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/services/auth-service/src/api/controllers/trade-password.controller.ts b/backend/services/auth-service/src/api/controllers/trade-password.controller.ts index 05c372c2..278ab1f7 100644 --- a/backend/services/auth-service/src/api/controllers/trade-password.controller.ts +++ b/backend/services/auth-service/src/api/controllers/trade-password.controller.ts @@ -7,22 +7,35 @@ import { HttpStatus, UseGuards, } from '@nestjs/common'; +import { IsString, IsNotEmpty } from 'class-validator'; import { ThrottlerGuard } from '@nestjs/throttler'; import { TradePasswordService } from '@/application/services/trade-password.service'; import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard'; import { CurrentUser } from '@/shared/decorators/current-user.decorator'; class SetTradePasswordDto { + @IsString() + @IsNotEmpty() loginPassword: string; + + @IsString() + @IsNotEmpty() tradePassword: string; } class ChangeTradePasswordDto { + @IsString() + @IsNotEmpty() oldTradePassword: string; + + @IsString() + @IsNotEmpty() newTradePassword: string; } class VerifyTradePasswordDto { + @IsString() + @IsNotEmpty() tradePassword: string; }