fix: 收紧演示模式与刷新预限流

This commit is contained in:
root
2026-09-15 00:00:06 +08:00
parent 6b453af364
commit b480d2c91f
5 changed files with 112 additions and 18 deletions
+9 -6
View File
@@ -221,6 +221,15 @@ export class AuthService {
retryAttempt = 0,
): Promise<TokenPair> {
if (!this.validRefreshShape(token)) throw this.invalid();
if (retryAttempt === 0)
await this.limitAll([
{
kind: "refresh-attempt-ip",
parts: [phoneHmac(ip)],
max: envInt("REFRESH_ATTEMPT_IP_LIMIT", 30),
ttl: envInt("REFRESH_ATTEMPT_IP_WINDOW_SECONDS", 60),
},
]);
const hash = refreshHmac(token);
const observed = await this.prisma.refreshToken.findUnique({
where: { tokenHash: hash },
@@ -241,12 +250,6 @@ export class AuthService {
max: envInt("REFRESH_RATE_LIMIT", 60),
ttl: 60,
},
{
kind: "refresh-ip",
parts: [phoneHmac(ip)],
max: envInt("REFRESH_RATE_LIMIT", 60),
ttl: 60,
},
]);
await this.cleanupExpiredRefreshTokens(observed.sessionId);
}