fix: 收口模板契约与安全门禁
统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
1 parent
456171aa85
commit
4f0b50c7f1
84 files changed
+7367
-5180
No files matched your search
+12
-2
@@ -1,7 +1,13 @@
|
||||
import { UnauthorizedException } from "@nestjs/common";
|
||||
import { createHmac, timingSafeEqual } from "node:crypto";
|
||||
|
||||
type Identity = { subject: string; brandId: string; role: "customer" | "admin"; exp: number };
|
||||
type Identity = {
|
||||
subject: string;
|
||||
brandId: string;
|
||||
role: "customer" | "admin";
|
||||
tokenVersion?: number;
|
||||
exp: number;
|
||||
};
|
||||
|
||||
function secret(): string {
|
||||
const value = process.env.SESSION_SECRET;
|
||||
@@ -14,7 +20,11 @@ export function signIdentity(
|
||||
ttlSeconds = 60 * 60 * 24 * 7,
|
||||
): string {
|
||||
const payload = Buffer.from(
|
||||
JSON.stringify({ ...identity, exp: Math.floor(Date.now() / 1000) + ttlSeconds }),
|
||||
JSON.stringify({
|
||||
...identity,
|
||||
tokenVersion: identity.tokenVersion ?? 0,
|
||||
exp: Math.floor(Date.now() / 1000) + ttlSeconds,
|
||||
}),
|
||||
).toString("base64url");
|
||||
const signature = createHmac("sha256", secret()).update(payload).digest("base64url");
|
||||
return `${payload}.${signature}`;
|
||||
|
||||
Reference in new issue
Block a user