收口 Phase 0 三处「声明未生效」: - 三级鉴权落地:权限集存 Redis(key 前缀隔离多项目),@RequirePermissions 挂到全部受控接口,super_admin 角色绕过权限码与 data_scope - 审计/登录日志自动落库:@AuditLog 装饰器 + 拦截器异步写入(写操作+登录登出),登录成功/失败均记 login_log(脱敏) - seed 脚本:一键初始化租户 touyun/用户 touyun/超管 super_admin/全量资源树(48 资源全量授权) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
20 lines
919 B
TypeScript
20 lines
919 B
TypeScript
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
||
import { Observable } from 'rxjs';
|
||
import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';
|
||
import { maskSensitive } from '../common/mask.js';
|
||
|
||
/** 记录请求 body(POST/PUT/PATCH/DELETE),敏感字段脱敏,级别 debug。 */
|
||
@Injectable()
|
||
export class BodyLoggingInterceptor implements NestInterceptor {
|
||
constructor(@InjectPinoLogger(BodyLoggingInterceptor.name) private readonly logger: PinoLogger) {}
|
||
|
||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||
const request = context.switchToHttp().getRequest();
|
||
const { method, url, body } = request;
|
||
if (body && ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method) && Object.keys(body).length > 0) {
|
||
this.logger.debug({ method, url, body: maskSensitive(body) }, 'request body');
|
||
}
|
||
return next.handle();
|
||
}
|
||
}
|