Skip to content

Commit bada144

Browse files
authored
lower rate limit in production much higher in dev and test (#25688)
* lower rate limit in production much higher in dev and test * custom rate limit for browser tests * feedbacked
1 parent bb1800a commit bada144

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

docker-compose.prod.tmpl.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
HEROKU_APP_NAME: ${HEROKU_APP_NAME}
1717
ENABLED_LANGUAGES: ${ENABLED_LANGUAGES}
1818
DEPLOYMENT_ENV: ${DEPLOYMENT_ENV}
19+
RATE_LIMIT_MAX: ${RATE_LIMIT_MAX}
1920
HEROKU_PRODUCTION_APP: true
2021
PORT: 4000
2122
DD_AGENT_HOST: datadog-agent

middleware/rate-limit.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import statsd from '../lib/statsd.js'
33

44
const EXPIRES_IN_AS_SECONDS = 60
55

6+
const MAX = process.env.RATE_LIMIT_MAX ? parseInt(process.env.RATE_LIMIT_MAX, 10) : 1000
7+
if (isNaN(MAX)) {
8+
throw new Error(`process.env.RATE_LIMIT_MAX (${process.env.RATE_LIMIT_MAX}) not a number`)
9+
}
10+
611
export default rateLimit({
712
// 1 minute
813
windowMs: EXPIRES_IN_AS_SECONDS * 1000,
@@ -13,7 +18,7 @@ export default rateLimit({
1318
// by the current number of instances.
1419
// We have see DDoS attempts against prod that hits the `/` endpoint
1520
// (and not following the redirect to `/en`) at roughly 200k per minute.
16-
max: process.env.NODE_ENV === 'test' ? 1000 : 100,
21+
max: MAX,
1722

1823
// Return rate limit info in the `RateLimit-*` headers
1924
standardHeaders: true,

0 commit comments

Comments
 (0)