1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

chore: rate limit calling inc webhooks (#6248)

https://linear.app/unleash/issue/2-1942/rate-limit-incoming-webhooks-call-endpoint

Adds a configurable rate limit to calling incoming webhooks. We're
setting a 1RPS limit for now, but I'm open to suggestions.
This commit is contained in:
Nuno Góis 2024-02-15 10:25:32 +00:00 committed by GitHub
parent 8dc27204d1
commit ef8d2edcc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 0 deletions

View File

@ -173,6 +173,7 @@ exports[`should create default config 1`] = `
"prometheusApi": undefined, "prometheusApi": undefined,
"publicFolder": undefined, "publicFolder": undefined,
"rateLimiting": { "rateLimiting": {
"callIncomingWebhookMaxPerSecond": 1,
"createUserMaxPerMinute": 20, "createUserMaxPerMinute": 20,
"simpleLoginMaxPerMinute": 10, "simpleLoginMaxPerMinute": 10,
}, },

View File

@ -142,10 +142,15 @@ function loadRateLimitingConfig(options: IUnleashOptions): IRateLimiting {
process.env.SIMPLE_LOGIN_LIMIT_PER_MINUTE, process.env.SIMPLE_LOGIN_LIMIT_PER_MINUTE,
10, 10,
); );
const callIncomingWebhookMaxPerSecond = parseEnvVarNumber(
process.env.INCOMING_WEBHOOK_RATE_LIMIT_PER_SECOND,
1,
);
const defaultRateLimitOptions: IRateLimiting = { const defaultRateLimitOptions: IRateLimiting = {
createUserMaxPerMinute, createUserMaxPerMinute,
simpleLoginMaxPerMinute, simpleLoginMaxPerMinute,
callIncomingWebhookMaxPerSecond,
}; };
return mergeAll([defaultRateLimitOptions, options.rateLimiting || {}]); return mergeAll([defaultRateLimitOptions, options.rateLimiting || {}]);
} }

View File

@ -206,6 +206,7 @@ export interface IMetricsRateLimiting {
export interface IRateLimiting { export interface IRateLimiting {
createUserMaxPerMinute: number; createUserMaxPerMinute: number;
simpleLoginMaxPerMinute: number; simpleLoginMaxPerMinute: number;
callIncomingWebhookMaxPerSecond: number;
} }
export interface IUnleashConfig { export interface IUnleashConfig {