fix(gateway): clamp auth limiter durations · openclaw/openclaw@54a27f4
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -108,6 +108,23 @@ describe("auth rate limiter", () => {
|
108 | 108 | } |
109 | 109 | }); |
110 | 110 | |
| 111 | +it("clamps oversized lockout durations", () => { |
| 112 | +vi.useFakeTimers(); |
| 113 | +try { |
| 114 | +limiter = createAuthRateLimiter({ |
| 115 | +maxAttempts: 1, |
| 116 | +windowMs: 60_000, |
| 117 | +lockoutMs: Number.MAX_SAFE_INTEGER, |
| 118 | +}); |
| 119 | + |
| 120 | +limiter.recordFailure("10.0.0.34"); |
| 121 | + |
| 122 | +expect(limiter.check("10.0.0.34").retryAfterMs).toBe(MAX_TIMER_TIMEOUT_MS); |
| 123 | +} finally { |
| 124 | +vi.useRealTimers(); |
| 125 | +} |
| 126 | +}); |
| 127 | + |
111 | 128 | // ---------- sliding window expiry ---------- |
112 | 129 | |
113 | 130 | it("expires old failures outside the window", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -109,8 +109,8 @@ function resolvePruneIntervalMs(value: number | undefined): number {
|
109 | 109 | |
110 | 110 | export function createAuthRateLimiter(config?: RateLimitConfig): AuthRateLimiter { |
111 | 111 | const maxAttempts = config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS; |
112 | | -const windowMs = config?.windowMs ?? DEFAULT_WINDOW_MS; |
113 | | -const lockoutMs = config?.lockoutMs ?? DEFAULT_LOCKOUT_MS; |
| 112 | +const windowMs = resolveTimerTimeoutMs(config?.windowMs, DEFAULT_WINDOW_MS, 0); |
| 113 | +const lockoutMs = resolveTimerTimeoutMs(config?.lockoutMs, DEFAULT_LOCKOUT_MS, 0); |
114 | 114 | const exemptLoopback = config?.exemptLoopback ?? true; |
115 | 115 | const pruneIntervalMs = resolvePruneIntervalMs(config?.pruneIntervalMs); |
116 | 116 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。