Rate limit: no IP shares a capped bucket; optional Turnstile hostname check
A request without a usable client IP used to skip every limiter. It now counts against one shared 'unknown-ip' bucket at 20x the limit. submitForm, createSubmitAction and verifyTurnstile accept turnstileHostnames/hostnames to reject tokens solved on another domain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10da62ea4c
commit
8e10232765
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, test, vi } from 'vitest'
|
||||
import {
|
||||
checkRateLimit,
|
||||
clientIp,
|
||||
UNKNOWN_IP_FACTOR,
|
||||
consumeRateLimit,
|
||||
setRateLimitStore,
|
||||
} from '../src/modules/shared/rateLimit.js'
|
||||
@@ -64,8 +65,10 @@ describe('checkRateLimit (in memory)', () => {
|
||||
expect(checkRateLimit({ cost: 4, key: `k-${Math.random()}`, max: 3 })).toBe(false)
|
||||
})
|
||||
|
||||
test('no key → allowed', () => {
|
||||
expect(checkRateLimit({ key: '', max: 0 })).toBe(true)
|
||||
test('no key → one shared bucket with a roomier limit, not a free pass', () => {
|
||||
const scope = `s-${Math.random()}`
|
||||
for (let i = 0; i < 2 * UNKNOWN_IP_FACTOR; i++) {expect(checkRateLimit({ key: '', max: 2, scope })).toBe(true)}
|
||||
expect(checkRateLimit({ key: '', max: 2, scope })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user