Spaces:
Running
Running
Download src/middleware/rateLimiters.js from AndreaNotes1/auth-app-api: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/AndreaNotes1/auth-app-api/resolve/main/src/middleware/rateLimiters.js
- Command line
-
hf download hf://spaces/AndreaNotes1/auth-app-api/src/middleware/rateLimiters.js
-
curl -L -o rateLimiters.js https://huggingface.co/spaces/AndreaNotes1/auth-app-api/resolve/main/src/middleware/rateLimiters.js
1.43 kB
| const rateLimit = require("express-rate-limit"); | |
| // General API traffic | |
| const apiLimiter = rateLimit({ | |
| windowMs: 15 * 60 * 1000, | |
| limit: 300, | |
| standardHeaders: true, | |
| legacyHeaders: false, | |
| message: { error: "Too many requests, please try again later." }, | |
| }); | |
| // Tight limits on auth endpoints to blunt credential stuffing / brute force | |
| const authLimiter = rateLimit({ | |
| windowMs: 15 * 60 * 1000, | |
| limit: 10, | |
| standardHeaders: true, | |
| legacyHeaders: false, | |
| skipSuccessfulRequests: true, | |
| message: { error: "Too many attempts. Please wait a few minutes and try again." }, | |
| }); | |
| // Checkout/order creation limiter to prevent order-spam / enumeration | |
| const orderLimiter = rateLimit({ | |
| windowMs: 60 * 60 * 1000, | |
| limit: 20, | |
| standardHeaders: true, | |
| legacyHeaders: false, | |
| message: { error: "Too many order attempts. Please try again later or contact support." }, | |
| }); | |
| // Voucher codes are bearer credentials, so redemption attempts are rate | |
| // limited per client the same way login attempts are, to blunt brute | |
| // forcing/guessing of codes. | |
| const voucherRedeemLimiter = rateLimit({ | |
| windowMs: 15 * 60 * 1000, | |
| limit: 15, | |
| standardHeaders: true, | |
| legacyHeaders: false, | |
| skipSuccessfulRequests: true, | |
| message: { error: "Too many voucher attempts. Please wait a few minutes and try again." }, | |
| }); | |
| module.exports = { apiLimiter, authLimiter, orderLimiter, voucherRedeemLimiter }; | |