ai-helper-agent 1.3.2 → 1.3.4
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/package.json +1 -1
- package/src/security.js +8 -6
package/package.json
CHANGED
package/src/security.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// agent/src/security.js - 安全管控:文件沙箱 + 命令分级
|
|
2
|
-
import { resolve, normalize, sep } from 'path';
|
|
2
|
+
import { resolve, normalize, sep, isAbsolute } from 'path';
|
|
3
3
|
import { realpathSync } from 'fs';
|
|
4
4
|
import { loadConfig } from './config.js';
|
|
5
5
|
|
|
@@ -14,10 +14,12 @@ function checkPath(pathStr) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
|
-
const
|
|
17
|
+
const config = loadConfig();
|
|
18
|
+
|
|
19
|
+
// 相对路径基于 config.workdir 解析,而非 process.cwd()
|
|
20
|
+
const resolved = isAbsolute(pathStr) ? resolve(pathStr) : resolve(config.workdir, pathStr);
|
|
18
21
|
const normalized = normalize(resolved);
|
|
19
22
|
|
|
20
|
-
const config = loadConfig();
|
|
21
23
|
const allowedPaths = config.allowedPaths.length > 0 ? config.allowedPaths : [config.workdir];
|
|
22
24
|
|
|
23
25
|
// 先做前缀检查(快速路径,兼容 Windows/Unix)
|
|
@@ -92,9 +94,9 @@ const BLACKLIST_PATTERNS = [
|
|
|
92
94
|
// 修改根目录权限
|
|
93
95
|
/^\s*chmod\s+(-R\s+)?(0?777|a\+rwx)\s+\//,
|
|
94
96
|
/^\s*chown\s+-R\s+\S+\s+\//,
|
|
95
|
-
// Shell
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
// Shell 命令替换注入 — 允许 echo/printf 等纯输出命令中使用
|
|
98
|
+
/^\s*(?!(echo|printf|cat|head|tail|wc|ls|pwd|date|whoami|hostname|uname|id|env|printenv|which|type)\s).*`[^`]*`/,
|
|
99
|
+
/^\s*(?!(echo|printf|cat|head|tail|wc|ls|pwd|date|whoami|hostname|uname|id|env|printenv|which|type)\s).*\$\s*\([^)]*\)/,
|
|
98
100
|
];
|
|
99
101
|
|
|
100
102
|
const SCRIPT_EXTENSIONS = '(sh|bash|zsh|py|js|mjs|rb|pl|php|lua)';
|