fix: 收口模板契约与安全门禁

统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
que01 committed 2026-10-18 22:05:31 +08:00
1 parent 456171aa85
commit 4f0b50c7f1
84 files changed
+7367 -5180

No files matched your search

+11 -14
View File
@@ -1,4 +1,4 @@
import { Injectable, UnauthorizedException } from "@nestjs/common";
import { ForbiddenException, Injectable, UnauthorizedException } from "@nestjs/common";
import bcrypt from "bcryptjs";
import { PrismaService } from "./prisma.service.js";
import { signIdentity } from "./auth.js";
@@ -29,24 +29,17 @@ export class AdminAuthService {
where: { adminUserId: user.id, isEnabled: true },
orderBy: { createdAt: "asc" },
});
const activeMembership =
membership ??
(await this.prisma.brandMembership.create({
data: {
adminUserId: user.id,
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
role: "owner",
},
}));
if (!membership) throw new ForbiddenException("管理员没有品牌权限,请先联系平台负责人分配");
return {
token: signIdentity({
subject: user.id,
brandId: activeMembership.brandId,
brandId: membership.brandId,
role: "admin",
tokenVersion: user.tokenVersion,
}),
displayName: user.displayName,
mustChangePassword: user.mustChangePassword,
role: activeMembership.role,
role: membership.role,
platformTemplateRole: user.platformTemplateRole,
};
}
@@ -57,12 +50,16 @@ export class AdminAuthService {
newPassword: string,
): Promise<void> {
const user = await this.prisma.adminUser.findUnique({ where: { id: userId } });
if (!user || !(await bcrypt.compare(currentPassword, user.passwordHash))) {
if (!user?.isEnabled || !(await bcrypt.compare(currentPassword, user.passwordHash))) {
throw new UnauthorizedException("当前密码不正确");
}
await this.prisma.adminUser.update({
where: { id: userId },
data: { passwordHash: await bcrypt.hash(newPassword, 12), mustChangePassword: false },
data: {
passwordHash: await bcrypt.hash(newPassword, 12),
mustChangePassword: false,
tokenVersion: { increment: 1 },
},
});
}
}