auto-smart-security 1.0.13 → 1.0.14

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.
@@ -9,6 +9,23 @@ const utils_1 = require("./utils");
9
9
  const bot_detector_1 = require("./bot-detector");
10
10
  const rate_limiter_1 = require("./rate-limiter");
11
11
  const memory_store_1 = require("./blacklist/memory.store");
12
+ const STATIC_EXTENSIONS = [
13
+ '.png',
14
+ '.jpg',
15
+ '.jpeg',
16
+ '.gif',
17
+ '.webp',
18
+ '.svg',
19
+ '.ico',
20
+ '.bmp',
21
+ '.css',
22
+ '.js',
23
+ '.map',
24
+ '.woff',
25
+ '.woff2',
26
+ '.ttf',
27
+ '.eot',
28
+ ];
12
29
  function applySecurity(app, options) {
13
30
  // Dev mode → skip security
14
31
  if (options.mode === 'dev')
@@ -44,6 +61,11 @@ function applySecurity(app, options) {
44
61
  });
45
62
  }));
46
63
  }
64
+ /** ================= IMAGES ================= */
65
+ const isStaticAsset = (url) => {
66
+ const path = url.split('?')[0].toLowerCase();
67
+ return STATIC_EXTENSIONS.some((ext) => path.endsWith(ext));
68
+ };
47
69
  /** ================= MAIN SECURITY ================= */
48
70
  app.use(async (req, res, next) => {
49
71
  // pass OPTIONS requests
@@ -51,12 +73,12 @@ function applySecurity(app, options) {
51
73
  return next();
52
74
  const ip = (0, utils_1.getClientIP)(req);
53
75
  const url = req.originalUrl;
54
- console.log('url =========>', url, ip, blacklist);
76
+ if (isStaticAsset(url))
77
+ return next();
55
78
  /** 1️⃣ Blacklist */
56
79
  if (await blacklist.isBlocked(ip)) {
57
80
  return res.status(403).send('Access denied');
58
81
  }
59
- console.log('run to here =========>', 1);
60
82
  /** 2️⃣ Bot detection */
61
83
  if (botDetector?.detect(req)) {
62
84
  await blacklist.block(ip);
@@ -68,14 +90,12 @@ function applySecurity(app, options) {
68
90
  });
69
91
  return res.status(403).send('Bot detected');
70
92
  }
71
- console.log('run to here =========>', 2);
72
93
  /** 3️⃣ Path whitelist */
73
94
  const normalizePath = (url) => url.split('?')[0].replace(/^\/+/, '');
74
95
  const isPathAllowed = (url, whitelist) => {
75
96
  const path = normalizePath(url);
76
97
  return whitelist.some((p) => path === p || path.includes(`${p}`));
77
98
  };
78
- console.log('run to here =========>', 3, options.pathWhitelist, url);
79
99
  if (options.pathWhitelist?.length &&
80
100
  !isPathAllowed(url, options.pathWhitelist)) {
81
101
  await blacklist.block(ip);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-smart-security",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Production-ready security middleware for Express / NestJS",
5
5
  "author": "Hai Vinh <haivinhinspirit@gmail.com>",
6
6
  "main": "dist/index.js",