auto-smart-security 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/apply-security.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ const redis = new Redis({
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
applySecurity(app, {
|
|
143
|
-
mode: process.env.NODE_ENV
|
|
143
|
+
mode: process.env.NODE_ENV === 'development' ? 'dev' : 'prod',
|
|
144
144
|
rateLimit: { max: 120, windowMs: 60_000 },
|
|
145
145
|
bot: { enabled: true },
|
|
146
146
|
blacklistTTL: 10 * 60 * 1000,
|
package/dist/apply-security.js
CHANGED
|
@@ -54,8 +54,13 @@ function applySecurity(app, options) {
|
|
|
54
54
|
return res.status(403).send('Bot detected');
|
|
55
55
|
}
|
|
56
56
|
/** 3️⃣ Path whitelist */
|
|
57
|
+
const normalizePath = (url) => url.split('?')[0].replace(/^\/+/, '');
|
|
58
|
+
const isPathAllowed = (url, whitelist) => {
|
|
59
|
+
const path = normalizePath(url);
|
|
60
|
+
return whitelist.some((p) => path.startsWith(p.replace(/^\/+/, '')));
|
|
61
|
+
};
|
|
57
62
|
if (options.pathWhitelist?.length &&
|
|
58
|
-
!options.pathWhitelist
|
|
63
|
+
!isPathAllowed(url, options.pathWhitelist)) {
|
|
59
64
|
await blacklist.block(ip);
|
|
60
65
|
options.onBlock?.({
|
|
61
66
|
ip,
|