Skip to content

Commit

Permalink
chore: rate limit calling inc webhooks (#6248)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nunogois authored Feb 15, 2024
1 parent 8dc2720 commit ef8d2ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ exports[`should create default config 1`] = `
"prometheusApi": undefined,
"publicFolder": undefined,
"rateLimiting": {
"callIncomingWebhookMaxPerSecond": 1,
"createUserMaxPerMinute": 20,
"simpleLoginMaxPerMinute": 10,
},
Expand Down
5 changes: 5 additions & 0 deletions src/lib/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ function loadRateLimitingConfig(options: IUnleashOptions): IRateLimiting {
process.env.SIMPLE_LOGIN_LIMIT_PER_MINUTE,
10,
);
const callIncomingWebhookMaxPerSecond = parseEnvVarNumber(
process.env.INCOMING_WEBHOOK_RATE_LIMIT_PER_SECOND,
1,
);

const defaultRateLimitOptions: IRateLimiting = {
createUserMaxPerMinute,
simpleLoginMaxPerMinute,
callIncomingWebhookMaxPerSecond,
};
return mergeAll([defaultRateLimitOptions, options.rateLimiting || {}]);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export interface IMetricsRateLimiting {
export interface IRateLimiting {
createUserMaxPerMinute: number;
simpleLoginMaxPerMinute: number;
callIncomingWebhookMaxPerSecond: number;
}

export interface IUnleashConfig {
Expand Down

0 comments on commit ef8d2ed

Please sign in to comment.