sycommon-python-lib 0.2.7a17__py3-none-any.whl → 0.2.7a19__py3-none-any.whl
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.
- sycommon/agent/middleware/sandbox_path_guard.py +35 -18
- sycommon/agent/middleware/skill_write_guard.py +3 -2
- sycommon/agent/multi_agent_team.py +3 -0
- {sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/METADATA +1 -1
- {sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/RECORD +8 -8
- {sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/top_level.txt +0 -0
|
@@ -44,8 +44,10 @@ except Exception: # 测试/独立引入环境兜底,行为与 sandbox.py 保持
|
|
|
44
44
|
_WORKSPACE_ROOT = os.path.realpath(WORKSPACE_BASE).rstrip(os.sep)
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
# 工具 →
|
|
48
|
-
# get_share_url 是 app(base_tools)
|
|
47
|
+
# 工具 → 路径字段名(单字段)或多字段(列表)映射(结构化参数,可安全改写/拦截)。
|
|
48
|
+
# get_share_url 是 app(base_tools)自定义工具,吃 file_path;
|
|
49
|
+
# transfer_file 是 bridge/multi 模式注入的跨沙箱传输工具,吃 src_path + dst_path,
|
|
50
|
+
# 两个路径字段都要过同一套越权校验(否则 agent 可借它绕过,把别人的绝对路径文件传出来)。
|
|
49
51
|
_PATH_TOOLS = {
|
|
50
52
|
"read_file": "file_path",
|
|
51
53
|
"write_file": "file_path",
|
|
@@ -54,6 +56,7 @@ _PATH_TOOLS = {
|
|
|
54
56
|
"glob": "path",
|
|
55
57
|
"grep": "path",
|
|
56
58
|
"get_share_url": "file_path",
|
|
59
|
+
"transfer_file": ["src_path", "dst_path"],
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
# 宿主沙箱根前缀(用于 execute 命令串扫描;shell 里无法安全改写,只能拦)。
|
|
@@ -114,22 +117,36 @@ class SandboxPathGuardMiddleware(AgentMiddleware):
|
|
|
114
117
|
if not isinstance(args, dict):
|
|
115
118
|
return await handler(request)
|
|
116
119
|
|
|
117
|
-
# 1) 结构化路径工具:read/write/edit/ls/grep/glob/get_share_url
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
# 1) 结构化路径工具:read/write/edit/ls/grep/glob/get_share_url/transfer_file
|
|
121
|
+
# 字段规格可为单字段(str)或多字段(list);多字段工具(如 transfer_file
|
|
122
|
+
# 的 src_path+dst_path)任一字段越界即拦整个调用,防借传输绕过读他人文件。
|
|
123
|
+
fields_spec = _PATH_TOOLS.get(name)
|
|
124
|
+
if fields_spec:
|
|
125
|
+
fields = [fields_spec] if isinstance(fields_spec, str) else list(fields_spec)
|
|
126
|
+
rewrites = {} # field -> 改写后的虚拟路径
|
|
127
|
+
for field in fields:
|
|
128
|
+
raw = args.get(field)
|
|
129
|
+
if not isinstance(raw, str):
|
|
130
|
+
continue
|
|
131
|
+
# transfer_file 支持 sandbox:<名称>: 前缀指定源/目标沙箱,剥掉前缀再判路径本身
|
|
132
|
+
path_part = raw.split(":", 2)[-1] if raw.startswith("sandbox:") else raw
|
|
133
|
+
if not _is_host_absolute(path_part):
|
|
134
|
+
continue
|
|
135
|
+
if self._self_ws and _within_self_workspace(path_part, self._self_ws):
|
|
136
|
+
# 自己工作目录内的绝对路径 → 改写为虚拟路径(剥前缀后改写,前缀保留)
|
|
137
|
+
virtual = _to_virtual(path_part, self._self_ws)
|
|
138
|
+
rewrites[field] = (raw[:len(raw) - len(path_part)] + virtual) \
|
|
139
|
+
if raw.startswith("sandbox:") else virtual
|
|
140
|
+
else:
|
|
141
|
+
# 越界/跨用户宿主绝对路径 → 整个调用拦
|
|
142
|
+
return ToolMessage(content=_DENIED_MSG, name=name,
|
|
143
|
+
tool_call_id=tc.get("id", ""), status="error")
|
|
144
|
+
if rewrites:
|
|
145
|
+
new_args = dict(args)
|
|
146
|
+
new_args.update(rewrites)
|
|
147
|
+
new_tc = dict(tc)
|
|
148
|
+
new_tc["args"] = new_args
|
|
149
|
+
return await handler(dataclasses.replace(request, tool_call=new_tc))
|
|
133
150
|
return await handler(request)
|
|
134
151
|
|
|
135
152
|
# 2) execute(裸 shell):命令串里的宿主绝对路径无法安全改写,只能拦
|
|
@@ -21,8 +21,9 @@ _WRITE_VERB_RE = re.compile(
|
|
|
21
21
|
_REDIRECT_RE = re.compile(r'>>?')
|
|
22
22
|
|
|
23
23
|
_WRITE_TOOLS = {"write_file", "edit_file"}
|
|
24
|
-
_DENIED_MSG = ("Error: 系统技能 /skills/system
|
|
25
|
-
"
|
|
24
|
+
_DENIED_MSG = ("Error: 系统技能 /skills/system 为只读,禁止写入/修改/删除。"
|
|
25
|
+
"读取(read_file)和执行脚本(python ...)不受限,直接用即可,不要把脚本复制到工作目录再跑。"
|
|
26
|
+
"如需修改脚本本身,复制到 /skills/user/ 后编辑。")
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
def _is_protected_path(p: str) -> bool:
|
|
@@ -46,6 +46,7 @@ from sycommon.agent.chat_events import ChatEvent, ChatEventBuilder, DEFAULT_AGEN
|
|
|
46
46
|
from sycommon.middleware.token_tracking import TokenTrackingMiddleware
|
|
47
47
|
from sycommon.middleware.tool_result_truncation import ToolResultTruncationMiddleware
|
|
48
48
|
from sycommon.agent.middleware.skill_write_guard import SkillWriteGuardMiddleware
|
|
49
|
+
from sycommon.agent.middleware.sandbox_path_guard import SandboxPathGuardMiddleware
|
|
49
50
|
from sycommon.agent.middleware.sensitive_guard import (
|
|
50
51
|
SensitiveGuardMiddleware, DowngradeState,
|
|
51
52
|
)
|
|
@@ -643,6 +644,7 @@ async def create_multi_agent_team(
|
|
|
643
644
|
TokenTrackingMiddleware(model_name=config.model_name, user_id=user_id),
|
|
644
645
|
summarization_mw,
|
|
645
646
|
SkillWriteGuardMiddleware(),
|
|
647
|
+
SandboxPathGuardMiddleware(user_id),
|
|
646
648
|
]
|
|
647
649
|
shared = config.shared_tools or [get_current_date]
|
|
648
650
|
|
|
@@ -701,6 +703,7 @@ async def create_multi_agent_team(
|
|
|
701
703
|
TokenTrackingMiddleware(model_name=config.model_name, user_id=user_id),
|
|
702
704
|
coord_summarization_mw,
|
|
703
705
|
SkillWriteGuardMiddleware(),
|
|
706
|
+
SandboxPathGuardMiddleware(user_id),
|
|
704
707
|
],
|
|
705
708
|
)
|
|
706
709
|
|
|
@@ -137,7 +137,7 @@ sycommon/agent/__init__.py,sha256=mxceAeUifQ-DKvWp7ZEJIFlmOCb5wpYHPGQw3rwEN8I,43
|
|
|
137
137
|
sycommon/agent/agent_manager.py,sha256=UhhaekEumT7g4v_Z1UB4jTp13X0n8M8erYaQdkGGWkA,13620
|
|
138
138
|
sycommon/agent/chat_events.py,sha256=t7qWa6OrIWLfqtd1AnqaVP67QWkn1JxpCBTZYQpoLuM,14226
|
|
139
139
|
sycommon/agent/deep_agent.py,sha256=kj4E1FT2vnSTWsfXgBymFa9iSokrUKLXnsPhxMsZNS4,74741
|
|
140
|
-
sycommon/agent/multi_agent_team.py,sha256=
|
|
140
|
+
sycommon/agent/multi_agent_team.py,sha256=RFXHB9q5j1_2B-MDZVRTcbXHdEpRIXpAhrm1yroUDYI,30460
|
|
141
141
|
sycommon/agent/summarization_utils.py,sha256=bqZRFqSekNGlv2mYQPaT_s2QNA5VDTKddi2Va_SkHWc,18376
|
|
142
142
|
sycommon/agent/acp/__init__.py,sha256=vQGMQYAA5-ZaejYmDZ4r4Fklqs17qH3cDXQ5pZlwj-0,1844
|
|
143
143
|
sycommon/agent/acp/client.py,sha256=s-K626b9ierwyEq61gejrW0xOysvrY2PIpYFsFqSHjc,27108
|
|
@@ -147,12 +147,12 @@ sycommon/agent/acp/tool.py,sha256=yt6ohKL2y7wIZMNiLv-m5oCg5u1p5GAbqgjzQVt285Y,10
|
|
|
147
147
|
sycommon/agent/mcp/__init__.py,sha256=iKrdDhIrFsNIkqG_kgcwNe-nOiM6uVfolKv44LfQ-FQ,636
|
|
148
148
|
sycommon/agent/mcp/models.py,sha256=zda4ho-UTYOJ5oPAZPZ-vxhfDRLghUCsMroHnA2A2QQ,1490
|
|
149
149
|
sycommon/agent/mcp/tool_loader.py,sha256=OQa-lE7RL2s3Lqh-kNOKaUrb130hvorB_HjyFBqZBZs,10960
|
|
150
|
-
sycommon/agent/middleware/sandbox_path_guard.py,sha256=
|
|
150
|
+
sycommon/agent/middleware/sandbox_path_guard.py,sha256=5hgtf-9aqJ16BQuDwda3gXL12RbwPcexhYQPEV6H33M,7684
|
|
151
151
|
sycommon/agent/middleware/sensitive_guard.py,sha256=ApmC094ogG4jIwEWRaUawTpQSDs722k0OTjdeAEQ7Qc,22159
|
|
152
152
|
sycommon/agent/middleware/sitecustomize.py,sha256=Bt7XFnWV_LJo89l858AGp5VUkXwefpLGmjkCtLe-CMw,4800
|
|
153
153
|
sycommon/agent/middleware/skill_api_whitelist.py,sha256=e15aJekXegPp64owSCEdUE5y0SmwCQVQCF4jnhReZNU,10958
|
|
154
154
|
sycommon/agent/middleware/skill_wl_check.py,sha256=rCJ9F6aWPh8tVQBIPmcq2lKDsfwiJQduwSUku_8kXfs,3952
|
|
155
|
-
sycommon/agent/middleware/skill_write_guard.py,sha256=
|
|
155
|
+
sycommon/agent/middleware/skill_write_guard.py,sha256=ZbeRysGBqn0knjmDWRgPu7c8Pr5lGnjFgeEpAukSSWQ,2702
|
|
156
156
|
sycommon/agent/sandbox/__init__.py,sha256=jR7LlkD4J4Y6QYyRXQClkwmqDBCCPmycV_hQV9p9YHw,4621
|
|
157
157
|
sycommon/agent/sandbox/consistent_hash.py,sha256=8Jgk-W4NAD2-u5_vKRVlPmql_e0Vy4aNORiXOuzvIrs,7277
|
|
158
158
|
sycommon/agent/sandbox/file_ops.py,sha256=XDqqNFlPh-VN28prkR0BSqDvebrQ_fjUDyNwqKOo-is,33805
|
|
@@ -308,8 +308,8 @@ sycommon/tools/syemail.py,sha256=BDFhgf7WDOQeTcjxJEQdu0dQhnHFPO_p3eI0-Ni3LhQ,561
|
|
|
308
308
|
sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
|
|
309
309
|
sycommon/xxljob/__init__.py,sha256=7eoBlQxv-B39IfRSCY2bkqdGYs1QRe1umAWd88VMEEM,86
|
|
310
310
|
sycommon/xxljob/xxljob_service.py,sha256=1yifwIBNGsCIxLnQjHKiBlbsigc_zvPH-dMTZcNxe-Q,7649
|
|
311
|
-
sycommon_python_lib-0.2.
|
|
312
|
-
sycommon_python_lib-0.2.
|
|
313
|
-
sycommon_python_lib-0.2.
|
|
314
|
-
sycommon_python_lib-0.2.
|
|
315
|
-
sycommon_python_lib-0.2.
|
|
311
|
+
sycommon_python_lib-0.2.7a19.dist-info/METADATA,sha256=bWoOxTQOS_rExoQGN-smQxnK-c6utsTEfK5SauR7Ar4,7962
|
|
312
|
+
sycommon_python_lib-0.2.7a19.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
313
|
+
sycommon_python_lib-0.2.7a19.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
|
|
314
|
+
sycommon_python_lib-0.2.7a19.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
|
|
315
|
+
sycommon_python_lib-0.2.7a19.dist-info/RECORD,,
|
|
File without changes
|
{sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{sycommon_python_lib-0.2.7a17.dist-info → sycommon_python_lib-0.2.7a19.dist-info}/top_level.txt
RENAMED
|
File without changes
|