@@ -6,16 +6,28 @@ export class AttackWaveDetector {
66 private suspiciousRequestsMap : LRUMap < string , number > ;
77 private sentEventsMap : LRUMap < string , number > ;
88
9+ // How many suspicious requests are allowed before triggering an alert
10+ private readonly attackWaveThreshold : number ;
11+ // In what time frame must these requests occur
12+ private readonly attackWaveTimeFrame : number ;
13+ // Minimum time before reporting a new event for the same ip
14+ private readonly minTimeBetweenEvents : number ;
15+ // Maximum number of entries in the LRU cache
16+ private readonly maxLRUEntries : number ;
17+
918 constructor (
10- // How many suspicious requests are allowed before triggering an alert
11- private readonly attackWaveThreshold = 6 ,
12- // In what time frame must these requests occur
13- private readonly attackWaveTimeFrame = 60 * 1000 , // 60 seconds
14- // Minimum time before reporting a new event for the same ip
15- private readonly minTimeBetweenEvents = 60 * 60 * 1000 , // 1 hour
16- // Maximum number of entries in the LRU cache
17- private readonly maxLRUEntries = 10_000
19+ options : {
20+ attackWaveThreshold ?: number ;
21+ attackWaveTimeFrame ?: number ;
22+ minTimeBetweenEvents ?: number ;
23+ maxLRUEntries ?: number ;
24+ } = { }
1825 ) {
26+ this . attackWaveThreshold = options . attackWaveThreshold ?? 6 ; // Default: 6 requests
27+ this . attackWaveTimeFrame = options . attackWaveTimeFrame ?? 60 * 1000 ; // Default: 1 minute
28+ this . minTimeBetweenEvents = options . minTimeBetweenEvents ?? 60 * 60 * 1000 ; // Default: 1 hour
29+ this . maxLRUEntries = options . maxLRUEntries ?? 10_000 ; // Default: 10,000 entries
30+
1931 this . suspiciousRequestsMap = new LRUMap (
2032 this . maxLRUEntries ,
2133 this . attackWaveTimeFrame
0 commit comments