agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:LocalFilesystemSpec能引导agent读取不同会话窗口的产物

Open oyx888 opened this issue 2 months ago • 4 comments

agent是单例模式。 环境配置 LocalFilesystemSpec localSpec = new LocalFilesystemSpec() .project(Path.of(resolvedWorkspace)) .isolationScope(IsolationScope.SESSION); agentBuilder.filesystem(localSpec); 再补充一点,是引导agent执行shell命令,然后获取到不同窗口的产物,这样会涉及到隐私问题

[
    {
        "role": "system",
        "parts": [
            {
                "type": "text",
                "content": "## AgentStateStore Context\nThis is the 个人助手. We are setting up the context for our chat.\nToday's date is 星期三 9月 23, 2026.\nMy operating system is: Windows 10 10.0\nThe workspace directory is: D:\\workspace\\hc_1\\session_13\nThe project's temporary directory is: C:\\Users\\ASUS\\AppData\\Local\\Temp\\\nAgentStateStore ID: session_13\n\n## Domain Knowledge\nThe workspace `knowledge/` tree holds many detailed reference documents (not only a single summary file). When the task needs specs, procedures, schemas, or domain facts, treat that directory as the source of truth.\nBelow, `<domain_knowledge_context>` already includes what you need to navigate it: injected `knowledge/KNOWLEDGE.md` (if present) plus a **full list of knowledge file paths** under `knowledge/` — use that as the catalog of what exists and where.\nFor content not inlined here, open only the paths you need with read_file, grep, or glob (prefer targeted reads over loading entire trees into the reply).\n\n## Memory Recall\nBefore answering questions about prior work, decisions, dates, people, or preferences: run memory_search on MEMORY.md + memory/*.md, then memory_get for needed lines. Include Source: <path#line> citations when helpful.\n\n## Memory Persistence\nYou have a persistent MEMORY.md. Update it proactively when:\n- User shares preferences, project context, or decisions\n- Important outcomes or action items are established\nUse the **memory_save** tool to persist memories — it atomically updates both MEMORY.md and the daily ledger. Do NOT use write_file or edit_file on MEMORY.md or any path under memory/ — always use memory_save instead.\nMemory is also automatically extracted at conversation end.\n\n## Workspace\nProject (the user's source tree you're assisting with): D:\\workspace\\hc_1\nWorkspace (your home base — memory, sessions, skills, runtime data): D:\\workspace\\hc_1\\session_13\nPath access policy: ROOTED (absolute paths accepted only inside the roots above). File tools reject absolute paths outside the roots above with a security error.\nRelative paths resolve under the workspace and read-fall-back to the project (overlay copy-on-write).\nShell commands run with `pwd` set to the project directory.\nAGENTS.md defines persona and local conventions — honor them when consistent with safety and policy.\n\n## Workspace Files (Injected)\nThe following <loaded_context> was loaded in from files in your workspace.\nThese files (for example, `AGENTS.md`, `MEMORY.md`, and `knowledge/KNOWLEDGE.md`) contain memory, facts, preferences, guidelines, and user-specific details learned from prior interactions with user.\n\n<loaded_context>\n  <agents_context></agents_context>\n  <memory_context></memory_context>\n  <domain_knowledge_context></domain_knowledge_context>\n</loaded_context>\n## Available Skills\n\n<usage>\nSkills provide specialized capabilities and domain knowledge. Use them when they match your current task.\n\nHow to use skills:\n- Load skill: load_skill_through_path(skillId=\"<skill-id>\", path=\"SKILL.md\")\n- The skill will be activated and its documentation loaded with detailed instructions\n- Additional resources (scripts, assets, references) can be loaded with the same tool and other paths\n\nExample:\n1. User asks to analyze data -> find a matching skill below (e.g. <skill-id>data-analysis_workspace</skill-id>)\n2."
            }
        ],
        "name": "system"
    },
    {
        "role": "user",
        "parts": [
            {
                "type": "text",
                "content": "帮我列出工作区的目录"
            }
        ]
    },
    {
        "role": "assistant",
        "parts": [
            {
                "type": "tool_call",
                "id": "call_6be82e774f244a159e58161f",
                "name": "list_files",
                "arguments": "{\"path\": \"D:\\\\workspace\\\\hc_1\\\\session_13\"}"
            }
        ],
        "name": "个人助手."
    },
    {
        "role": "tool",
        "parts": [
            {
                "type": "tool_call_response",
                "id": "call_6be82e774f244a159e58161f",
                "response": [
                    {
                        "text": "\"[DIR]  /.skills-cache/\\n[DIR]  /session_10/\\n[DIR]  /session_11/\\n[DIR]  /session_12/\\n[DIR]  /session_9/\\n[FILE] /测试文档.docx (5183 bytes)\\n[FILE] /测试文档_2026.docx (5185 bytes)\""
                    }
                ]
            }
        ],
        "name": "个人助手."
    },
    {
        "role": "assistant",
        "parts": [
            {
                "type": "text",
                "content": "工作区目录 `D:\\workspace\\hc_1\\session_13` 的内容如下:\n\n**目录:**\n- `.skills-cache/` - 技能缓存目录\n- `session_10/` - 会话 10 目录\n- `session_11/` - 会话 11 目录\n- `session_12/` - 会话 12 目录\n- `session_9/` - 会话 9 目录\n\n**文件:**\n- `测试文档.docx` (5183 字节)\n- `测试文档_2026.docx` (5185 字节)\n\n如果您需要查看某个特定目录或文件的详细内容,请告诉我!"
            }
        ],
        "name": "个人助手."
    },
    {
        "role": "user",
        "parts": [
            {
                "type": "text",
                "content": "看下session_9/ 有什么文件"
            }
        ]
    }
]
{
  "param": {
    "id": "call_f16c2aa8691e435a8843390b",
    "name": "list_files",
    "input": {
      "path": "D:\\workspace\\hc_1\\session_13\\session_9"
    },
    "content": "{\"path\": \"D:\\\\workspace\\\\hc_1\\\\session_13\\\\session_9\"}",
    "metadata": {},
    "state": "pending"
  }
}
{
  "type": "tool_result",
  "id": null,
  "name": null,
  "output": [
    {
      "type": "text",
      "text": "\"[FILE] /session_9/MEMORY.md (556 bytes)\\n[DIR]  /session_9/agents/\\n[DIR]  /session_9/default/\\n[FILE] /session_9/excel_1790081475534.xlsx (4712 bytes)\\n[FILE] /session_9/excel_1790081491247.xlsx (5473 bytes)\\n[FILE] /session_9/excel_1790081495058.xlsx (5631 bytes)\\n[FILE] /session_9/excel_1790081498246.xlsx (5790 bytes)\\n[FILE] /session_9/excel_1790081508233.xlsx (5861 bytes)\\n[FILE] /session_9/excel_1790081512288.xlsx (5983 bytes)\\n[FILE] /session_9/excel_1790081514306.xlsx (5988 bytes)\\n[DIR]  /session_9/memory/\\n[FILE] /session_9/ppt_1790082392329.pptx (36971 bytes)\\n[FILE] /session_9/月度工作总结报告.docx (5826 bytes)\""
    }
  ],
  "metadata": {},
  "state": "running"
}

oyx888 avatar Sep 23 '26 08:09 oyx888

Issue Evaluation

Category: bug / area/harness | Status: Confirmed (security-relevant: cross-session data leak)

Reproduced in the code against main @ ed77530a4 (static review of the local filesystem + isolation path).

Root cause: with LocalFilesystemSpec, IsolationScope.SESSION is a path prefix, not an access boundary.

  1. IsolationScope (agentscope-harness/src/main/java/io/agentscope/harness/agent/IsolationScope.java:53, values SESSION/USER/AGENT/GLOBAL at :62/:71/:78/:87) documents only two effects: the sandbox _sandbox.json state key and the remote filesystem store namespace prefix. Nothing in it claims read-root confinement for a local filesystem, and docs/v2/en/docs/harness/filesystem.md:389-398 reads the same way.
  2. The scope is turned into a namespace factory (IsolationScope.java:102-126, SESSION -> [sessionId]) and passed into LocalFilesystemSpec.toFilesystem(...) (LocalFilesystemSpec.java:288-306). The prefix is applied in LocalFilesystem.resolvePath -> applyNamespacePrefix (LocalFilesystem.java:596-607, :689-707) — but :698 deliberately returns absolute paths unchanged ("Absolute paths identify specific host locations and must not be namespace-scoped"). So a relative list_files(".") lands in workspace/<sessionId>/, while an absolute path bypasses session scoping entirely.
  3. The roots checked by the ROOTED policy are [project, workspace, additionalRoots] (LocalFilesystemSpec.java:291-295), and ROOTED accepts any absolute path that starts with the filesystem root dir (LocalFilesystem.java:633-640). In this configuration the root dir is the parent that contains every session_N, and the injected system prompt even names it explicitly (WorkspaceContextMiddleware.java:331-334, :350-354). Reading hc_1\session_9 from session_13 therefore passes the check by design — OverlayFilesystem adds no extra gate for ls/read/grep/glob (OverlayFilesystem.java:140, :162-164, :198, :221). The .. validation (AbstractFilesystem.validatePath:178-188) does not help here, because the absolute path is the working vector, not a traversal.

Impact: one session can silently enumerate and read another session's MEMORY.md, memory/, agents/ and generated artifacts (docx/xlsx/pptx) from the same agent instance. Since SESSION is advertised for "each conversation fully isolated" multi-tenant use, in any deployment that treats it as a boundary this is effectively a cross-tenant read primitive. Severity: high. Mitigating context: the local + shell mode is documented for trusted single-process hosts where the model already has sh -c, so the exposure is bounded by that assumption — which is exactly the assumption the configuration makes misleading.

Fix direction (needs a maintainer decision, so not sending an automated patch for this one):

  • Either make the effective root the namespace-resolved directory for session/user-scoped local filesystems — i.e. derive the ROOTED check and PathPolicy roots from workspace/<ns> and keep the project layer read-only —
  • or reject absolute keys that resolve inside another namespace when isolationScope is SESSION/USER, returning the existing rootAccessDenied security error so the model sees an explicit refusal instead of a successful cross-session listing.
  • The cheaper alternative is documentation-only: stop presenting SESSION as an isolation guarantee for LocalFilesystemSpec and state that absolute paths are intentionally unsandboxed. Given AGENT/GLOBAL exist, a real boundary is probably the less surprising outcome, so the docs-only route is a last resort.

Could a harness owner confirm which of these is intended before a fix is written? If the answer is "enforce a real boundary", we can generate the change plus tests for the root/path-policy computation.


Automated evaluation by github-manager-bot

oss-maintainer avatar Sep 23 '26 09:09 oss-maintainer

Opened PR #3292 implementing the "reject absolute keys that resolve inside another namespace" direction from the evaluation: LocalFilesystem gains an opt-in namespaceBoundary that, in ROOTED mode, requires absolute paths resolving under the workspace root to stay inside cwd/<namespace> (the leading-slash virtual form is covered too); LocalFilesystemSpec enables it for the workspace layer. Project-layer and additionalRoots paths outside the workspace root are unaffected, and the check is a no-op when no namespace is active. Full agentscope-harness suite passes (1062 tests). One design point flagged in the PR for maintainer input: with a namespace active, absolute access to shared workspace-root dirs (e.g. skills/) is rejected as well, since they are indistinguishable from a sibling session's directory — shared content stays reachable via workspace-relative paths.

chang6666 avatar Sep 25 '26 11:09 chang6666

Hi, I'd like to work on this. Investigating the cross-session artifact visibility in LocalFilesystemSpec — the report suggests the namespace/scoping path leaks artifacts across session windows. Will post root-cause analysis and a scoped fix. PR coming shortly.

aiyili avatar Oct 23 '26 07:10 aiyili

Withdrawal — apologies for the noise: PR #3292 by @chang6666 already implements the evaluation's direction (opt-in namespaceBoundary enforcing that ROOTED absolute paths resolving under the workspace stay inside cwd/<namespace>), which I missed before claiming. Nothing further from me on this issue; #3261 should close via #3292.

aiyili avatar Oct 26 '26 02:10 aiyili