auto-smart-security 1.0.2 → 1.0.4

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 CHANGED
@@ -140,7 +140,7 @@ const redis = new Redis({
140
140
  });
141
141
 
142
142
  applySecurity(app, {
143
- mode: process.env.NODE_ENV !== 'development' ? 'dev' : 'prod',
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,
@@ -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 === p || path.startsWith(`${p}/`));
61
+ };
57
62
  if (options.pathWhitelist?.length &&
58
- !options.pathWhitelist.some((p) => url.includes(p))) {
63
+ !isPathAllowed(url, options.pathWhitelist)) {
59
64
  await blacklist.block(ip);
60
65
  options.onBlock?.({
61
66
  ip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-smart-security",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Production-ready security middleware for Express / NestJS",
5
5
  "author": "Hai Vinh <haivinhinspirit@gmail.com>",
6
6
  "main": "dist/index.js",