@domain.js/main 0.7.7 → 0.7.8

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.
Files changed (2) hide show
  1. package/dist/http/utils.js +13 -1
  2. package/package.json +1 -1
@@ -34,6 +34,18 @@ const enc = encodeURI;
34
34
  const TMPDIR = os.tmpdir();
35
35
  function Utils(cnf) {
36
36
  const proxyIps = new Set((cnf.proxyIps || "127.0.0.1").split(","));
37
+ /**
38
+ * 判断是否是内网ip
39
+ * 10.0.0.0 - 10.255.255.255 (10/8 前缀)
40
+ * 172.16.0.0 - 172.31.255.255 (172.16/12 到 172.31/12 前缀)
41
+ * 192.168.0.0 - 192.168.255.255 (192.168/16 前缀)
42
+ */
43
+ const isInternalIp = (ip) => {
44
+ const parts = ip.split(".").map(Number);
45
+ return (parts[0] === 10 ||
46
+ (parts[0] === 192 && parts[1] === 168) ||
47
+ (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31));
48
+ };
37
49
  const utils = {
38
50
  ucwords(value) {
39
51
  return `${value[0].toUpperCase()}${value.substring(1)}`;
@@ -56,7 +68,7 @@ function Utils(cnf) {
56
68
  */
57
69
  realIp(req) {
58
70
  const remoteIp = utils.remoteIp(req);
59
- if (!proxyIps.has(remoteIp))
71
+ if (!proxyIps.has(remoteIp) && !isInternalIp(remoteIp))
60
72
  return remoteIp;
61
73
  return (req.headers["x-real-ip"] || remoteIp).toString();
62
74
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {