mocode-ai 1.4.1 → 1.4.2
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/dist/sandbox/jail.js +3 -3
- package/package.json +1 -1
package/dist/sandbox/jail.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 核心:resolve(root, input) → realpath(解软链)→ 前缀校验。
|
|
3
3
|
// 新文件(目标不存在)走「最近存在祖先 realpath 再拼回剩余分量」,同样挡住「祖先是出圈软链」。
|
|
4
4
|
import { realpathSync, existsSync } from 'node:fs';
|
|
5
|
-
import { resolve, relative, isAbsolute, dirname, basename, join } from 'node:path';
|
|
5
|
+
import { resolve, relative, isAbsolute, dirname, basename, join, posix, win32 } from 'node:path';
|
|
6
6
|
import { getSandboxRoot } from './root.js';
|
|
7
7
|
const isWin = process.platform === 'win32';
|
|
8
8
|
/** 当前沙箱根(绝对),未初始化回退 process.cwd()。 */
|
|
@@ -59,14 +59,14 @@ export function jailResolve(input) {
|
|
|
59
59
|
return abs;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* glob pattern
|
|
62
|
+
* glob pattern 校验:同时拒绝 POSIX/Windows 绝对路径与含 `..` 段的 pattern。
|
|
63
63
|
* 返 null = 通过;返 string = 拒绝原因。形如 *.ts 的正常 pattern 放行。
|
|
64
64
|
*/
|
|
65
65
|
export function jailGlobPattern(pattern) {
|
|
66
66
|
const p = String(pattern ?? '').trim();
|
|
67
67
|
if (!p)
|
|
68
68
|
return '空 pattern';
|
|
69
|
-
if (isAbsolute(p))
|
|
69
|
+
if (posix.isAbsolute(p) || win32.isAbsolute(p))
|
|
70
70
|
return `不得为绝对路径: ${pattern}`;
|
|
71
71
|
const segs = p.split(/[\\/]/);
|
|
72
72
|
if (segs.includes('..'))
|