@maiyunnet/kebab 9.26.5 → 9.27.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.
package/lib/undici.js CHANGED
@@ -710,6 +710,17 @@ export async function rproxy(ctr, route, opt = {}) {
710
710
  : parsed.pathname;
711
711
  proxyUrl = prefix + (newQueryStr ? '?' + newQueryStr : '') + (parsed.hash ? '#' + parsed.hash : '');
712
712
  }
713
+ // --- 路径和查询参数不能改变配置的代理目标 ---
714
+ try {
715
+ const target = new URL(route[key]);
716
+ const result = new URL(proxyUrl);
717
+ if ((target.protocol !== 'http:' && target.protocol !== 'https:') || result.origin !== target.origin) {
718
+ return false;
719
+ }
720
+ }
721
+ catch {
722
+ return false;
723
+ }
713
724
  // --- 发起请求(opt.body 优先于原始 req 流) ---
714
725
  const rres = await request(proxyUrl, opt.body ?? req, {
715
726
  ...opt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "9.26.5",
3
+ "version": "9.27.1",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/child.js CHANGED
@@ -48,7 +48,7 @@ const hbTimer = setInterval(function () {
48
48
  */
49
49
  const certList = new Map();
50
50
  /** --- servername → certList mapKey 索引缓存 --- */
51
- let certHostIndex = {};
51
+ const certHostIndex = new Map();
52
52
  /** --- 最后一次加载证书到内存的时间 --- */
53
53
  let certLastLoad = 0;
54
54
  /** --- 当前的虚拟主机配置列表 - 读取于 conf/vhost/*.json --- */
@@ -118,7 +118,7 @@ async function run() {
118
118
  lCore.display('[CHILD][run] reloadCert error', e);
119
119
  });
120
120
  }
121
- const cachedKey = certHostIndex[servername];
121
+ const cachedKey = certHostIndex.get(servername);
122
122
  if (cachedKey !== undefined) {
123
123
  cb(null, certList.get(cachedKey).sc);
124
124
  return;
@@ -130,7 +130,7 @@ async function run() {
130
130
  }
131
131
  // --- 找到 ---
132
132
  cb(null, item.sc);
133
- certHostIndex[servername] = mapKey;
133
+ certHostIndex.set(servername, mapKey);
134
134
  return;
135
135
  }
136
136
  lCore.display(`[CHILD][SNICallback] CERT NOT FOUND for servername: ${servername}`);
@@ -254,6 +254,14 @@ async function requestHandler(req, res, https) {
254
254
  res.end('403 Forbidden');
255
255
  return;
256
256
  }
257
+ // --- 匹配虚拟主机后即记录,反代和提前响应也属于访问 ---
258
+ lCore.log({
259
+ 'req': req,
260
+ 'headers': req.headers,
261
+ 'hostname': uri.hostname ?? '',
262
+ 'urlFull': `${uri.protocol ?? ''}//${uri.host ?? ''}`,
263
+ 'path': uri.path ?? '/',
264
+ }, '', '-visit');
257
265
  // --- 配置来自 JSON,仅布尔值 true 开放内置示例 ---
258
266
  const debug = lCore.globalConfig.debug;
259
267
  if (debug !== true && await isExamplePath(vhost.real)) {
@@ -315,7 +323,6 @@ async function requestHandler(req, res, https) {
315
323
  'hostname': uri.hostname ?? '',
316
324
  'req': req,
317
325
  'get': uri.query ? lText.queryParse(uri.query) : {},
318
- 'cookie': {},
319
326
  'headers': {},
320
327
  }, '[CHILD][requestHandler][E0]' + lText.stringifyError(e), '-error');
321
328
  const content = '<h1>500 Server Error</h1>';
@@ -407,6 +414,13 @@ async function upgradeHandler(req, socket, https, head) {
407
414
  socket.end();
408
415
  return;
409
416
  }
417
+ lCore.log({
418
+ 'req': req,
419
+ 'headers': req.headers,
420
+ 'hostname': uri.hostname ?? '',
421
+ 'urlFull': `${uri.protocol ?? ''}//${uri.host ?? ''}`,
422
+ 'path': uri.path ?? '/',
423
+ }, '', '-visit');
410
424
  const debug = lCore.globalConfig.debug;
411
425
  if (debug !== true && await isExamplePath(vhost.real)) {
412
426
  socket.end();
@@ -577,7 +591,7 @@ async function reloadCert() {
577
591
  }
578
592
  }
579
593
  }
580
- certHostIndex = {};
594
+ certHostIndex.clear();
581
595
  }
582
596
  /**
583
597
  * --- 停止接收新连接,并在现有请求、上传、异步任务和 WebSocket 全部结束后退出 worker ---
package/sys/cmd.js CHANGED
@@ -10,7 +10,8 @@ import * as lFs from '#kebab/lib/fs.js';
10
10
  import * as lText from '#kebab/lib/text.js';
11
11
  import * as lTime from '#kebab/lib/time.js';
12
12
  import * as lCore from '#kebab/lib/core.js';
13
- import * as lCrypto from '#kebab/lib/crypto.js';
13
+ import * as rpc from '#kebab/lib/core/rpc.js';
14
+ import * as crypto from 'node:crypto';
14
15
  import * as kebab from '#kebab/index.js';
15
16
  // --- 检查语言包:node ./source/main locale -l ./source/www/example/data/locale/sc -d ./source/www/example ---
16
17
  /** --- 解析命令 --- */
@@ -75,7 +76,7 @@ async function run() {
75
76
  config.httpPort ??= 8080;
76
77
  config.httpsPort ??= 4333;
77
78
  config.rpcPort ??= 10630;
78
- config.rpcSecret ??= 'MUSTCHANGE';
79
+ config.rpcSecret ??= crypto.randomBytes(32).toString('hex');
79
80
  config.debug ??= true;
80
81
  config.max ??= 64;
81
82
  config.hosts ??= [];
@@ -584,10 +585,10 @@ async function run() {
584
585
  http.request({
585
586
  'hostname': '127.0.0.1',
586
587
  'port': config.rpcPort,
587
- 'path': '/' + lCrypto.aesEncrypt(lText.stringifyJson({
588
+ 'path': '/' + rpc.sign({
588
589
  'action': cmds[0],
589
590
  'time': time
590
- }), lCore.globalConfig.rpcSecret)
591
+ }, lCore.globalConfig.rpcSecret)
591
592
  }, function (res) {
592
593
  res.on('data', function (chunk) {
593
594
  const str = chunk.toString();
package/sys/ctr.js CHANGED
@@ -325,7 +325,7 @@ export class Ctr {
325
325
  if (!hydrate) {
326
326
  return html;
327
327
  }
328
- const propsJson = lText.stringifyJson(fullProps).replace(/<\/script>/gi, '<\\/script>');
328
+ const propsJson = lText.stringifyJson(fullProps).replace(/</g, '\\u003c');
329
329
  const clientUrl = `${staticPath}${path}.page.bundle.js?v=${this._config.set.staticVer}`;
330
330
  const propsScript = `<script id="__kebab_props__" type="application/json">${propsJson}</script>`;
331
331
  const hydrateScript = `<script type="module">import'${clientUrl}';</script>`;