Skip to content

Commit c53921d

Browse files
committed
Use object for options instead
1 parent cb1f755 commit c53921d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

library/vulnerabilities/attack-wave-detection/AttackWaveDetector.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ function getTestContext(
2525
}
2626

2727
function newAttackWaveDetector() {
28-
return new AttackWaveDetector(6, 60 * 1000, 60 * 60 * 1000, 10_000);
28+
return new AttackWaveDetector({
29+
attackWaveThreshold: 6,
30+
attackWaveTimeFrame: 60 * 1000,
31+
minTimeBetweenEvents: 60 * 60 * 1000,
32+
maxLRUEntries: 10_000,
33+
});
2934
}
3035

3136
t.test("no ip address", async (t) => {

library/vulnerabilities/attack-wave-detection/AttackWaveDetector.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)