express-range-tracker
Advanced tools
Comparing version 1.0.7 to 1.0.8
37
index.js
const defaultStorage = {}; | ||
const prop = (key) => (obj) => obj[key]; | ||
module.exports = ( | ||
@@ -12,2 +14,3 @@ { | ||
onDeadlineReached, | ||
onSimilarTimestamp, | ||
timestampFunction, | ||
@@ -103,2 +106,36 @@ bannedTraits = [], | ||
if (typeof onSimilarTimestamp === "function") { | ||
const reducer = | ||
(ip) => | ||
(acc, { timestamp }, index, arr) => { | ||
if (index) { | ||
acc.push({ | ||
ip, | ||
window: timestamp - arr[index - 1].timestamp, | ||
}); | ||
} | ||
return acc; | ||
}; | ||
const timestampWindows = Object.keys(storage) | ||
.filter((key) => storage[key].ip !== ip) | ||
.map((key) => storage[key].reduce(reducer(key), [])); | ||
const currentTimestampWindow = storage[ip] | ||
.reduce(reducer(ip), []) | ||
.map(prop("window")) | ||
.join(); | ||
const similarTimestampWindows = timestampWindows.filter( | ||
(chunks) => | ||
chunks.map(prop("window")).join() === currentTimestampWindow && | ||
chunks[0]?.ip !== ip | ||
); | ||
if (currentTimestampWindow && similarTimestampWindows.length) { | ||
onSimilarTimestamp(req, similarTimestampWindows.flat().map(prop("ip"))); | ||
} | ||
} | ||
if (typeof onSimilarTrait === "function") { | ||
@@ -105,0 +142,0 @@ const reducer = (acc, { from, to }) => (acc += `${from},${to};`); |
{ | ||
"name": "express-range-tracker", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Detects bots by tracking the timings of range header", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -73,2 +73,8 @@ # express-range-tracker | ||
`onSimilarTimestamp` - function that fires on clients with same range request timestamp windows | ||
```js | ||
onSimilarTimestamp(req, ips); | ||
``` | ||
# Test | ||
@@ -75,0 +81,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6624
146
84
0