File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
library/vulnerabilities/attack-wave-detection Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export type SuspiciousRequest = {
88} ;
99
1010export class AttackWaveDetector {
11- private suspiciousRequestsCounts : LRUMap < string , number > ;
11+ private suspiciousRequestsCounts : LRUMap < string , number [ ] > ;
1212 private suspiciousRequestsSamples : LRUMap < string , SuspiciousRequest [ ] > ;
1313 private sentEventsMap : LRUMap < string , number > ;
1414
@@ -80,14 +80,24 @@ export class AttackWaveDetector {
8080 return false ;
8181 }
8282
83- const suspiciousRequests = ( this . suspiciousRequestsCounts . get ( ip ) || 0 ) + 1 ;
84- this . suspiciousRequestsCounts . set ( ip , suspiciousRequests ) ;
83+ const currentTime = performance . now ( ) ;
84+ const requestTimestamps = this . suspiciousRequestsCounts . get ( ip ) || [ ] ;
85+
86+ const filteredTimestamps = requestTimestamps . filter (
87+ ( timestamp ) => currentTime - timestamp <= this . attackWaveTimeFrame
88+ ) ;
89+
90+ filteredTimestamps . push ( currentTime ) ;
91+
92+ this . suspiciousRequestsCounts . set ( ip , filteredTimestamps ) ;
8593
8694 this . trackSample ( ip , {
8795 method : context . method ,
8896 url : context . url ,
8997 } ) ;
9098
99+ const suspiciousRequests = filteredTimestamps . length ;
100+
91101 if ( suspiciousRequests < this . attackWaveThreshold ) {
92102 return false ;
93103 }
You can’t perform that action at this time.
0 commit comments