mm_os 4.3.6 → 5.0.0

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