mm_os 4.3.7 → 5.0.1

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 (231) hide show
  1. package/README.md +102 -504
  2. package/index.js +26 -19
  3. package/lib/os.js +536 -0
  4. package/package.json +60 -84
  5. package/LICENSE +0 -21
  6. package/README_EN.md +0 -505
  7. package/adapter/adapter.js +0 -484
  8. package/adapter/custom_persistence.js +0 -661
  9. package/adapter/mqtt.js +0 -254
  10. package/adapter/socket.js +0 -244
  11. package/adapter/web.js +0 -92
  12. package/adapter/websocket.js +0 -43
  13. package/ai.js +0 -130
  14. package/com/api/README.md +0 -3
  15. package/com/api/com.json +0 -5
  16. package/com/api/config.tpl.json +0 -41
  17. package/com/api/drive.js +0 -732
  18. package/com/api/index.js +0 -201
  19. package/com/api/oauth.js +0 -200
  20. package/com/api/script.tpl.js +0 -32
  21. package/com/cmd/README.md +0 -11
  22. package/com/cmd/com.json +0 -5
  23. package/com/cmd/config.tpl.json +0 -48
  24. package/com/cmd/drive.js +0 -176
  25. package/com/cmd/index.js +0 -287
  26. package/com/cmd/job/config.json +0 -66
  27. package/com/cmd/job/index.js +0 -241
  28. package/com/cmd/job/test.js +0 -188
  29. package/com/cmd/msg.json +0 -48
  30. package/com/cmd/script.tpl.js +0 -12
  31. package/com/db/README.md +0 -3
  32. package/com/db/com.json +0 -5
  33. package/com/db/drive.js +0 -2206
  34. package/com/db/index.js +0 -241
  35. package/com/event/README.md +0 -4
  36. package/com/event/com.json +0 -5
  37. package/com/event/config.tpl.json +0 -20
  38. package/com/event/drive.js +0 -61
  39. package/com/event/index.js +0 -438
  40. package/com/event/script.tpl.js +0 -23
  41. package/com/mqtt/README.md +0 -47
  42. package/com/mqtt/com.json +0 -5
  43. package/com/mqtt/config.tpl.json +0 -42
  44. package/com/mqtt/drive.js +0 -704
  45. package/com/mqtt/index.js +0 -1052
  46. package/com/mqtt/index.test.js +0 -503
  47. package/com/mqtt/script.tpl.js +0 -719
  48. package/com/nav/README.md +0 -2
  49. package/com/nav/com.json +0 -5
  50. package/com/nav/config.tpl.json +0 -84
  51. package/com/nav/drive.js +0 -702
  52. package/com/nav/index.js +0 -228
  53. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  54. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  55. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  56. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  57. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  58. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  59. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  60. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  61. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  62. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  63. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  64. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  66. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  67. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  68. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  69. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  70. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  71. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  73. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  74. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  75. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  76. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  77. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  78. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  80. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  81. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  82. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  83. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  84. package/com/nav/viewmodel.js +0 -446
  85. package/com/param/README.md +0 -2
  86. package/com/param/com.json +0 -5
  87. package/com/param/config.tpl.json +0 -136
  88. package/com/param/drive.js +0 -502
  89. package/com/param/index.js +0 -158
  90. package/com/param/script.tpl.js +0 -12
  91. package/com/pendant/README.md +0 -3
  92. package/com/pendant/com.json +0 -5
  93. package/com/pendant/config.tpl.json +0 -32
  94. package/com/pendant/drive.js +0 -204
  95. package/com/pendant/index.js +0 -467
  96. package/com/pendant/pendant.html +0 -16
  97. package/com/pendant/script.tpl.js +0 -18
  98. package/com/socket/README.md +0 -47
  99. package/com/socket/com.json +0 -5
  100. package/com/socket/config.tpl.json +0 -12
  101. package/com/socket/drive.js +0 -679
  102. package/com/socket/index.js +0 -402
  103. package/com/socket/script.tpl.js +0 -41
  104. package/com/sql/README.md +0 -3
  105. package/com/sql/com.json +0 -5
  106. package/com/sql/config.tpl.json +0 -74
  107. package/com/sql/drive.js +0 -1328
  108. package/com/sql/index.js +0 -152
  109. package/com/sql/script.tpl.js +0 -47
  110. package/com/static/README.md +0 -2
  111. package/com/static/com.json +0 -5
  112. package/com/static/config.tpl.json +0 -24
  113. package/com/static/drive.js +0 -194
  114. package/com/static/index.js +0 -237
  115. package/com/static/script.tpl.js +0 -28
  116. package/com/task/README.md +0 -3
  117. package/com/task/com.json +0 -5
  118. package/com/task/config.tpl.json +0 -24
  119. package/com/task/drive.js +0 -428
  120. package/com/task/index.js +0 -159
  121. package/com/task/script.tpl.js +0 -40
  122. package/com/template/com.json +0 -5
  123. package/com/template/config.tpl.json +0 -16
  124. package/com/template/drive.js +0 -81
  125. package/com/template/index.js +0 -141
  126. package/com.js +0 -237
  127. package/common/README.md +0 -2
  128. package/common/middleware/web_after/index.js +0 -26
  129. package/common/middleware/web_after/middleware.json +0 -9
  130. package/common/middleware/web_base/index.js +0 -113
  131. package/common/middleware/web_base/middleware.json +0 -19
  132. package/common/middleware/web_before/index.js +0 -33
  133. package/common/middleware/web_before/middleware.json +0 -9
  134. package/common/middleware/web_cors/index.js +0 -87
  135. package/common/middleware/web_cors/middleware.json +0 -24
  136. package/common/middleware/web_error/index.js +0 -131
  137. package/common/middleware/web_error/middleware.json +0 -19
  138. package/common/middleware/web_ip/index.js +0 -15
  139. package/common/middleware/web_ip/middleware.json +0 -14
  140. package/common/middleware/web_logger/index.js +0 -156
  141. package/common/middleware/web_logger/middleware.json +0 -14
  142. package/common/middleware/web_main/index.js +0 -26
  143. package/common/middleware/web_main/middleware.json +0 -9
  144. package/common/middleware/web_static/index.js +0 -73
  145. package/common/middleware/web_static/middleware.json +0 -54
  146. package/common/middleware/web_waf/index.js +0 -395
  147. package/common/middleware/web_waf/middleware.json +0 -13
  148. package/core/app/config.tpl.json +0 -67
  149. package/core/app/index.js +0 -711
  150. package/core/app/script.tpl.js +0 -52
  151. package/core/channel/index.js +0 -899
  152. package/core/channel/matcher.js +0 -585
  153. package/core/com/config.tpl.json +0 -16
  154. package/core/com/index.js +0 -77
  155. package/core/com/script.tpl.js +0 -5
  156. package/core/component/component.js +0 -42
  157. package/core/component/config.tpl.json +0 -63
  158. package/core/component/index.js +0 -273
  159. package/core/component/script.tpl.js +0 -19
  160. package/core/controller/config.tpl.json +0 -14
  161. package/core/controller/index.js +0 -371
  162. package/core/controller/script.tpl.js +0 -27
  163. package/core/factory/config.tpl.json +0 -14
  164. package/core/factory/entity.js +0 -275
  165. package/core/factory/index.js +0 -241
  166. package/core/factory/script.tpl.js +0 -16
  167. package/core/game/bat/index.js +0 -137
  168. package/core/game/bat/world.js +0 -622
  169. package/core/game/config.tpl.json +0 -16
  170. package/core/game/entity_admin.js +0 -230
  171. package/core/game/index.js +0 -186
  172. package/core/handler/config.tpl.json +0 -22
  173. package/core/handler/index.js +0 -181
  174. package/core/handler/script.tpl.js +0 -23
  175. package/core/logic/config.tpl.json +0 -14
  176. package/core/logic/index.js +0 -59
  177. package/core/logic/script.tpl.js +0 -19
  178. package/core/middleware/config.tpl.json +0 -16
  179. package/core/middleware/index.js +0 -117
  180. package/core/middleware/script.tpl.js +0 -37
  181. package/core/mod/config.tpl.json +0 -22
  182. package/core/mod/index.js +0 -136
  183. package/core/mod/script.tpl.js +0 -34
  184. package/core/model/config.tpl.json +0 -219
  185. package/core/model/index.js +0 -272
  186. package/core/model/model.js +0 -27
  187. package/core/model/script.tpl.js +0 -20
  188. package/core/notifier/config.tpl.json +0 -14
  189. package/core/notifier/index.js +0 -77
  190. package/core/notifier/script.tpl.js +0 -20
  191. package/core/plugin/config.tpl.json +0 -36
  192. package/core/plugin/index.js +0 -267
  193. package/core/plugin/script.tpl.js +0 -51
  194. package/core/pusher/config.tpl.json +0 -14
  195. package/core/pusher/index.js +0 -158
  196. package/core/pusher/script.tpl.js +0 -20
  197. package/core/room/bat/index.js +0 -170
  198. package/core/room/bat/room.js +0 -524
  199. package/core/room/config.tpl.json +0 -20
  200. package/core/room/index.js +0 -249
  201. package/core/room/room.js +0 -61
  202. package/core/scene/config.tpl.json +0 -14
  203. package/core/scene/index.js +0 -467
  204. package/core/scene/loop.js +0 -1306
  205. package/core/scene/map.js +0 -28
  206. package/core/scene/script.tpl.js +0 -22
  207. package/core/sender/config.tpl.json +0 -14
  208. package/core/sender/index.js +0 -79
  209. package/core/sender/script.tpl.js +0 -20
  210. package/core/service/config.tpl.json +0 -14
  211. package/core/service/index.js +0 -100
  212. package/core/service/script.tpl.js +0 -25
  213. package/core/store/config.tpl.json +0 -26
  214. package/core/store/index.js +0 -1794
  215. package/core/store/script.tpl.js +0 -22
  216. package/core/system/config.tpl.json +0 -18
  217. package/core/system/index.js +0 -312
  218. package/core/system/script.tpl.js +0 -77
  219. package/core/view/config.tpl.json +0 -14
  220. package/core/view/index.js +0 -91
  221. package/core/view/script.tpl.js +0 -20
  222. package/core/zone/bat/index.js +0 -744
  223. package/core/zone/config.tpl.json +0 -54
  224. package/core/zone/index.js +0 -655
  225. package/core/zone/script.tpl.js +0 -10
  226. package/core/zone/zone_bat.js +0 -136
  227. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  228. package/os.js +0 -53
  229. package/server.js +0 -602
  230. package/ulits/id_gen.js +0 -134
  231. package/ulits/word.js +0 -206
@@ -1,395 +0,0 @@
1
- const rateLimit = require('mm_kernel/common/mod/filter/rate_limit/index.js');
2
- const ipBlock = require('mm_kernel/common/mod/filter/ip_block/index.js');
3
-
4
- /**
5
- * web防火墙
6
- */
7
- module.exports = {
8
- /**
9
- * 初始化
10
- * @param {object} adapter 适配器集合
11
- */
12
- _init(adapter) {
13
- // 获取web服务
14
- var web = adapter.web;
15
-
16
- // 获取配置
17
- let cg = { ...this.config, ...adapter.web.config };
18
-
19
- // 设置WAF中间件
20
- let self = this;
21
- web.use(async (ctx, next) => {
22
- let waf_check_ret = await self._handleWafCheck(ctx, cg);
23
- if (waf_check_ret) {
24
- await next();
25
- }
26
- });
27
- },
28
-
29
- /**
30
- * 处理WAF检查
31
- * @private
32
- * @param {object} ctx 上下文
33
- * @param {object} cg 配置
34
- * @returns {boolean} 是否通过检查
35
- */
36
- async _handleWafCheck(ctx, cg) {
37
- // 获取客户端IP
38
- var ip = this._getClientIp(ctx.req);
39
-
40
- // 获取请求路径
41
- let path = ctx.path;
42
-
43
- // 检查路径是否在白名单中
44
- if (this.isPathWhiteListed(path, cg)) {
45
- return true;
46
- }
47
-
48
- // IP黑白名单与频率限制检查
49
- if (!(await this._checkIpAccess(ip, cg))) {
50
- this._sendWafResponse(ctx, 403, '访问被WAF阻止,IP访问受限');
51
- return false;
52
- }
53
-
54
- // 检查基本攻击特征
55
- let danger = this.wafCheck(ctx.url);
56
- if (danger) {
57
- this._sendWafResponse(ctx, 403, '访问被WAF阻止,请求包含潜在的攻击特征', danger.toString());
58
- return false;
59
- }
60
-
61
- // 检查路径遍历攻击
62
- let path_trav_ret = this._checkPathTrav(ctx);
63
- if (path_trav_ret) {
64
- this._sendWafResponse(ctx, 403, '访问被WAF阻止,检测到路径遍历攻击尝试');
65
- return false;
66
- }
67
- return true;
68
- },
69
-
70
- /**
71
- * 检查IP访问权限
72
- * @private
73
- * @param {string} ip IP地址
74
- * @param {object} cg 配置对象
75
- * @returns {Promise<boolean>} 是否允许访问
76
- */
77
- async _checkIpAccess(ip, cg) {
78
- if (!ip) {
79
- return true;
80
- }
81
- try {
82
- if (await this._checkIpBlocked(ip, cg)) {
83
- return false;
84
- }
85
- return await this._checkRateLimit(ip, cg);
86
- } catch {
87
- return true;
88
- }
89
- },
90
-
91
- /**
92
- * 检查IP是否在黑名单中
93
- * @private
94
- * @param {string} ip IP地址
95
- * @param {object} cg 配置对象
96
- * @returns {Promise<boolean>} 是否被拦截
97
- */
98
- async _checkIpBlocked(ip, cg) {
99
- var blacklist = (cg && cg.web && cg.web.ip_blacklist) || [];
100
- if (blacklist.length === 0) {
101
- return false;
102
- }
103
- var ctx = { input: { ip: ip }, output: {}, meta: {} };
104
- var done = await ipBlock.main(ctx, { blacklist: blacklist });
105
- return done.blocked;
106
- },
107
-
108
- /**
109
- * 检查请求频率是否超限
110
- * @private
111
- * @param {string} ip IP地址
112
- * @param {object} cg 配置对象
113
- * @returns {Promise<boolean>} 是否允许访问
114
- */
115
- async _checkRateLimit(ip, cg) {
116
- var max_req = (cg && cg.web && cg.web.max_req_per_min) || 100;
117
- var ctx = { input: {}, output: {}, meta: {} };
118
- var done = await rateLimit.main(ctx, {
119
- key: 'waf:' + ip,
120
- max_requests: max_req,
121
- window_ms: 60000
122
- });
123
- return !done.blocked;
124
- },
125
-
126
- /**
127
- * 获取客户端IP
128
- * @private
129
- * @param {object} req 请求对象
130
- * @returns {string} 客户端IP
131
- */
132
- _getClientIp(req) {
133
- // 标准IP获取逻辑
134
- return req.headers['x-forwarded-for'] || req.headers['X-Forwarded-For'] ||
135
- req.connection.remoteAddress ||
136
- req.socket.remoteAddress ||
137
- req.connection.socket.remoteAddress;
138
- },
139
-
140
- /**
141
- * 检查路径遍历攻击
142
- * @private
143
- * @param {object} ctx 上下文
144
- * @returns {string|boolean} 检测到的攻击类型或false
145
- */
146
- _checkPathTrav(ctx) {
147
- var path = ctx.path;
148
-
149
- // 检查路径本身
150
- if (this.checkPathTrav(path)) {
151
- return '路径本身包含攻击特征: ' + path;
152
- }
153
- if (!this.isSafePath(path)) {
154
- return '路径不安全: ' + path;
155
- }
156
-
157
- // 检查请求参数
158
- var query_params = ctx.query;
159
- for (var k in query_params) {
160
- var val = query_params[k];
161
- if (typeof val === 'string' && this.checkPathTrav(val)) {
162
- return '查询参数包含攻击特征: ' + k + '=' + val;
163
- }
164
- }
165
-
166
- // 检查POST请求体
167
- if (ctx.method === 'POST' && ctx.request.body) {
168
- var body_content = JSON.stringify(ctx.request.body);
169
- if (this.checkPathTrav(body_content)) {
170
- return '请求体包含攻击特征';
171
- }
172
- }
173
-
174
- return false;
175
- },
176
-
177
- /**
178
- * 发送WAF响应
179
- * @private
180
- * @param {object} ctx 上下文
181
- * @param {number} status 状态码
182
- * @param {string} msg 消息
183
- * @param {string} [rule] 规则
184
- */
185
- _sendWafResponse(ctx, status, msg, rule) {
186
- ctx.status = status;
187
- ctx.body = {
188
- code: status,
189
- msg: msg,
190
- rule: rule
191
- };
192
- },
193
-
194
- /**
195
- * 获取SQL注入检测规则
196
- * @private
197
- * @returns {RegExp[]} SQL注入规则列表
198
- */
199
- _getSqlRules() {
200
- return [
201
- /select.+(from|limit)/i,
202
- /(?:(union(.*?)select))/i,
203
- /sleep\((\s*)(\d*)(\s*)\)/i,
204
- /group\s+by.+\(/i,
205
- /(?:from\W+information_schema\W)/i,
206
- /(?:(?:current_)user|database|schema|connection_id)\s*\(/i,
207
- /\s*or\s+.*=.*/i,
208
- /order\s+by\s+.*--$/i,
209
- /benchmark\((.*)\,(.*)\)/i,
210
- /base64_decode\(/i,
211
- /(?:(?:current_)user|database|version|schema|connection_id)\s*\(/i,
212
- /(?:etc\/\W*passwd)/i,
213
- /into(\s+)+(?:dump|out)file\s*/i
214
- ];
215
- },
216
-
217
- /**
218
- * 获取代码注入和XSS检测规则
219
- * @private
220
- * @returns {RegExp[]} 代码注入和XSS规则列表
221
- */
222
- _getCodeInjectRules() {
223
- return [
224
- /xwork.MethodAccessor/i,
225
- /(?:define|eval|file_get_contents|include|require|require_once)\(/i,
226
- /(?:shell_exec|phpinfo|system|passthru|preg_\w+|execute)\(/i,
227
- /(?:echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(/i,
228
- /\<(iframe|script|body|img|layer|div|meta|style|base|object|input)/i,
229
- /(onmouseover|onmousemove|onerror|onload)\=/i,
230
- /javascript:/i
231
- ];
232
- },
233
-
234
- /**
235
- * 获取路径遍历检测规则
236
- * @private
237
- * @returns {RegExp[]} 路径遍历规则列表
238
- */
239
- _getPathTravRules() {
240
- return [
241
- // 增强的路径遍历检测规则
242
- /\.\.\//i, // 基础 ../
243
- /\.\.\\/i, // Windows格式 ..\
244
- /\%2e\%2e\//i, // URL编码 ../
245
- /\%2e%2e\//i, // URL编码 ../
246
- /\%252e%252e%2f/i, // 双重URL编码 ../
247
- /\%252e\%252e\%2f/i, // 双重URL编码 ../
248
- /\.\%2e\//i, // 混合编码
249
- /\%2e\./i, // 变体形式
250
- /\%5c/i, // 反斜杠URL编码
251
- /\%255c/i, // 反斜杠双重URL编码
252
- // 系统文件路径检测 - 改进以避免误判
253
- new RegExp('(?:\\/etc\\/|\\/proc\\/|C:\\\\Windows\\|' +
254
- 'C:\\\\winnt\\|C:\\\\Program Files\\|\\/sys\\/)', 'i')
255
- ];
256
- },
257
-
258
- /**
259
- * 获取命令注入检测规则
260
- * @private
261
- * @returns {RegExp[]} 命令注入规则列表
262
- */
263
- _getCmdInjectRules() {
264
- return [
265
- // 命令注入检测
266
- new RegExp('\\|\\|.*(?:ls|pwd|whoami|ll|ifconfog|' +
267
- 'ipconfig|&&|chmod|cd|mkdir|rmdir|cp|mv)', 'i'),
268
- new RegExp('(?:ls|pwd|whoami|ll|ifconfog|ipconfig|' +
269
- '&&|chmod|cd|mkdir|rmdir|cp|mv).*\\|\\|', 'i'),
270
- new RegExp('(gopher|doc|php|glob|file|phar|zlib|ftp|' +
271
- 'ldap|dict|ogg|data)\\:\/', 'i')
272
- ];
273
- },
274
-
275
- /**
276
- * 获取WAF规则列表
277
- * @private
278
- * @returns {RegExp[]} WAF规则列表
279
- */
280
- _getWafRules() {
281
- return [
282
- ...this._getSqlRules(),
283
- ...this._getCodeInjectRules(),
284
- ...this._getPathTravRules(),
285
- ...this._getCmdInjectRules()
286
- ];
287
- },
288
-
289
- /**
290
- * 使用正则表达式,检测字符串是否含有攻击特征,检测到攻击特征返回true,没检测到返回false
291
- * @param {string} url 网址
292
- * @returns {RegExp|null} 检测到的攻击规则或null
293
- */
294
- wafCheck(url) {
295
- var rules = this._getWafRules();
296
- for (var i = 0; i < rules.length; i++) {
297
- if (rules[i].test(url)) {
298
- return rules[i];
299
- }
300
- }
301
- return null;
302
- },
303
-
304
- /**
305
- * 检查路径是否包含路径遍历攻击
306
- * @param {string} path 路径
307
- * @returns {boolean} 是否包含路径遍历
308
- */
309
- checkPathTrav(path) {
310
- // 处理URL编码变体
311
- let url_decoded = decodeURIComponent(path);
312
- let double_url_decoded = decodeURIComponent(url_decoded);
313
-
314
- // 检查路径是否包含危险模式
315
- let danger_patterns = [
316
- '../', '../../', '../../../', // Unix/Linux格式
317
- '..\\', '..\\\\', '..\\\\\\\\', // Windows格式
318
- '/%2e%2e/', '/%2e%2e%2f', // URL编码变体
319
- '\\%2e%2e\\', '\\%2e%2e\\\\' // Windows URL编码变体
320
- ];
321
-
322
- // 检查系统关键文件路径(绝对路径攻击)
323
- let sys_paths = [
324
- '/etc/passwd', '/etc/shadow', '/etc/group', '/etc/hosts',
325
- '/proc/', '/bin/', '/usr/bin/',
326
- 'C:\\Windows\\', 'C:\\winnt\\', 'C:\\Program Files\\'
327
- ];
328
-
329
- // 检查原始路径、单次解码和双重解码后的路径
330
- // 1. 检查相对路径遍历模式
331
- let has_trav_pattern = danger_patterns.some(pattern =>
332
- path.includes(pattern) ||
333
- url_decoded.includes(pattern) ||
334
- double_url_decoded.includes(pattern)
335
- );
336
-
337
- // 2. 检查绝对路径攻击(包含系统关键文件路径)
338
- let has_abs_attack = sys_paths.some(sys_path =>
339
- path.toLowerCase().includes(sys_path.toLowerCase()) ||
340
- url_decoded.toLowerCase().includes(sys_path.toLowerCase()) ||
341
- double_url_decoded.toLowerCase().includes(sys_path.toLowerCase())
342
- );
343
-
344
- return has_trav_pattern || has_abs_attack; // 移除starts_with_slash检查
345
- },
346
-
347
- /**
348
- * 检查请求路径是否规范化,防止路径遍历攻击
349
- * @param {string} path 请求路径
350
- * @returns {boolean} 是否为安全路径
351
- */
352
- isSafePath(path) {
353
- // 特殊处理根路径,直接返回安全
354
- if (path === '/') {
355
- return true;
356
- }
357
-
358
- // 获取规范化的路径
359
- let norm_path = path.split('/')
360
- .filter(segment => segment !== '')
361
- .reduce((acc, segment) => {
362
- // 防止路径回溯
363
- if (segment === '..') {
364
- acc.pop();
365
- } else if (segment !== '.') {
366
- acc.push(segment);
367
- }
368
- return acc;
369
- }, [])
370
- .join('/');
371
-
372
- // 重新构建规范化的完整路径
373
- let safe_path = '/' + norm_path;
374
-
375
- // 检查规范化后的路径长度是否小于原始路径(表示存在路径回溯)
376
- return safe_path.length >= path.length - 2; // 允许末尾的 '/' 差异
377
- },
378
-
379
- /**
380
- * 检查路径是否在白名单中
381
- * @param {string} path 请求路径
382
- * @param {object} config WAF配置
383
- * @returns {boolean} 是否在白名单中
384
- */
385
- isPathWhiteListed(path, config) {
386
- // 获取配置中的路径白名单
387
- let path_white_list = (config && config.web && config.web.path_whitelist)
388
- || (config && config.path_whitelist)
389
- || ['/static', '/favicon.ico', '/api', '/public', '/assets'];
390
-
391
- // 检查路径是否以白名单中的任何路径开头
392
- return Array.isArray(path_white_list) &&
393
- path_white_list.some(white_path => path.startsWith(white_path));
394
- }
395
- };
@@ -1,13 +0,0 @@
1
- {
2
- "name": "web_waf",
3
- "title": "web防火墙",
4
- "description": "用于防止sql注入、脚本注入等",
5
- "version": "1.0",
6
- "main": "index.js",
7
- "type": "web",
8
- "state": 1,
9
- "sort": 50,
10
- "log": true,
11
- "ip_whitelist": ["127.0.0.1", "::1", "localhost"],
12
- "path_whitelist": ["/favicon.ico", "/static", "/api", "/public", "/assets"]
13
- }
@@ -1,67 +0,0 @@
1
- {
2
- // 名称
3
- "name": "${name}",
4
- // 标题
5
- "title": "${title || '示例标题'}",
6
- // 描述
7
- "description": "${description || '示例描述'}",
8
- // 版本号
9
- "version": "${version || '1.0.0'}",
10
- // 作者
11
- "author": "${author || 'qww'}",
12
- // 主文件
13
- "main": "${main || 'index.js'}",
14
- // 作用域,决定加载到什么区域(server/client/both)
15
- "scope": "${scope || 'server'}",
16
- // 状态 0:禁用 1:启用
17
- "state": 1,
18
- // 排序,越小越靠前
19
- "sort": 100,
20
- // 依赖的npm module
21
- "dependencies": [],
22
- // 检索的目录
23
- "dir": "${dir || ''}",
24
- // 是否为游戏应用
25
- "is_game": false,
26
- // // 游戏配置,非游戏模块不需要配置
27
- // "game": {
28
- // // 游戏类型
29
- // "type": "card_game"
30
- // },
31
- // 自定义数据库 - 1 开启 0 关闭
32
- "diy_sql": 0,
33
- // 自定义缓存 - 1 开启 0 关闭
34
- "diy_cache": 0,
35
- // sql 配置 - 可以没有,没有则使用默认数据库
36
- "sql": {
37
- // 数据库方式
38
- "way": "mysql",
39
- "mysql": {
40
- // 数据库主机
41
- "host": "127.0.0.1",
42
- // 数据库端口
43
- "port": 3306,
44
- // 数据库用户名
45
- "username": "root",
46
- // 数据库密码
47
- "password": "your_db_password_here",
48
- // 数据库名称
49
- "database": "mm"
50
- }
51
- },
52
- // 缓存配置 - 可以没有,没有则使用默认缓存
53
- "cache": {
54
- // 缓存方式方式
55
- "way": "redis",
56
- "redis": {
57
- // 缓存主机
58
- "host": "127.0.0.1",
59
- // 缓存端口
60
- "port": 6379,
61
- // 缓存密码
62
- "password": "your_redis_password_here",
63
- // 缓存数据库
64
- "database": 0
65
- }
66
- }
67
- }