refactor(rate-limit): delegate auth limiting to handlers, add dev bypass
Main's middleware-level auth limiter (5 req / 5 min, IP-only) duplicated
the handler-level limiter introduced earlier on this branch (5/hr IP +
3/hr per-email, blocks email enumeration across IPs). Drop the
middleware version and let the handlers own it.
Added ALLOW_DEV_TEST_ENDPOINTS bypass to the rateLimit utility so
parallel E2E runs from 127.0.0.1 don't exhaust per-IP/email budgets,
mirroring the existing middleware bypass.
Trimmed the obsolete middleware auth test; handler-level coverage lives
in tests/server/api/auth-{login,verify}.test.js. Switched IP-isolation
test to the payment path so it still exercises the limiter.
This commit is contained in:
parent
c1367ebd29
commit
4d44e7045c
3 changed files with 13 additions and 44 deletions
|
|
@ -4,6 +4,11 @@
|
|||
const buckets = new Map()
|
||||
|
||||
export function rateLimit(key, { max, windowMs }) {
|
||||
// Bypass in test/dev opt-in mode so parallel E2E runs from a single IP
|
||||
// (127.0.0.1) don't exhaust per-IP/email budgets. Mirrors the gate used by
|
||||
// /api/dev/* endpoints and server/middleware/03.rate-limit.js.
|
||||
if (process.env.ALLOW_DEV_TEST_ENDPOINTS === 'true') return true
|
||||
|
||||
const now = Date.now()
|
||||
|
||||
// Probabilistic sweep: ~1% of calls evict keys whose newest entry has fully
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue