Skip to content

fix(harness): keep file enumeration inside the caller's namespace - #4071

Merged
juruoO-o merged 7 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/namespace-path-boundaries
Dec 2, 2026
Merged

juruoO-o merged 7 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/namespace-path-boundaries

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT, based on main at 593a4662.

Description

Fixes #4069.

When the local workspace is nested under the project, project-layer scans can expose other users' namespaced files. Blank paths also previously resolved to the shared workspace root. Resolve a blank path inside the caller's namespace, and hide the workspace subtree from both the project read layer and the project-writable route when namespace scoping is enabled.

Listings and searches skip the hidden subtree; content operations treat it as absent, including through symbolic links. Recursive delete and directory move refuse an ancestor containing it, and an aliased spelling of that ancestor is resolved to its physical path before the check. Moves between two project paths run in the project layer, which is the one that knows the subtree is hidden. Ripgrep exclusions escape directory names such as work[1], and returned paths are checked again. The caller's workspace stays reachable through its own layer.

Reads now check the workspace, then the project write layer, then the shared project. Absolute project paths are left to the project layers: the workspace layer answered for files above its own root under a ../ spelling, so the same file came back twice under two keys. Enumeration treats a refused layer as contributing nothing instead of letting a SecurityException escape, and applies the same position check to each directory entry, including a junction, which is not a symbolic link. A refused root closes only from above, so a caller whose namespace list is empty still enumerates its own root. The classifier and the router normalize a relative key the same way, so ./MEMORY.md no longer lands in the project layer.

Reads ask the workspace layer before the project layers, so a project write under a key the workspace already holds would succeed and leave the caller reading the other file; that write, its edit, an upload and a move to the same key are refused, naming the workspace copy with its stamp and size; absolute spellings are exempt, because there the workspace layer answers only through the shared path policy. Metadata keys are exempt, because there the workspace copy is what reads return by design. delete keeps its project-first route, so this PR does not change which copy a delete removes. Listings merge on a normalized entry rather than on the spelling (a virtual layer reports /src/, a rooted one src/), so an entry is listed once and the upper copy wins. Search resolves each directory once per search instead of once per reported line. Shell execution keeps its project-rooted behavior; the class doc and the guide state that the shell, like hard links, sits outside this boundary.

Validation on Windows, Java 17:

  • Namespace boundary, overlay and write-shadow suites: 68 tests, 0 failures/errors, no skips; Spotless passed.
  • Harness module on this head: 2,385 tests, 0 failures/errors, 52 skipped; Spotless passed.
  • build (ubuntu-latest) and build (windows-latest) passed on e4b07aeb.
  • Each regression fails when its fix is reverted: the alias delete/read assertions, the sibling-absolute listing, the empty-namespace listing, the junction enumeration, the ./-prefixed route, the link move, the alias-rooted workspace, the shadowed project write, upload and move, the absolute project spelling, the workspace-absolute spelling, and the project-root enumeration.
  • Docs: the filesystem guide in docs/dev, Chinese and English (the 2.0 snapshot documents the release it came from).

Checklist

  • Code has been formatted; Spotless checks pass.
  • Tests pass for the commands and scopes listed above.
  • Javadoc comments follow project conventions.
  • Related English and Chinese documentation has been updated.
  • Code is ready for review.

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 2 times, most recently from ad023a5 to a748821 Compare November 8, 2026 11:55
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 2 times, most recently from 3a8ddb6 to a54c342 Compare November 8, 2026 19:01
@mintlify

mintlify Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit e4b07ae.

Approve preview

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 2 times, most recently from 21cb9e3 to 0f3b41a Compare November 8, 2026 20:03
@jujn jujn added the P0 重要紧急 label Nov 10, 2026
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 4 times, most recently from 1cc7342 to dbcd323 Compare November 10, 2026 23:31

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复方向和将内容访问一起纳入隐藏边界的范围合理,但 ripgrep 分支仍存在目录名含 glob 元字符时的隔离缺口,需先修复下方问题。验证边界:已实际检查 rg 对该模式编译出的 regex;跨用户影响来自调用链分析,本轮未搭建完整 Harness 端到端复现。

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 head f30dc70,基线为本次 fetch 的 main@c627cc7c9。

上次提出的 ripgrep glob 字面量转义和返回路径复核已补齐;在与最新 main 的干净合并快照上,59 个相关文件系统测试通过。但新增的祖先目录删除保护仍可通过符号链接别名绕过,存在跨用户数据删除风险,需先修复下方 P1。

验证:独立探针经公开 LocalFilesystemSpec.projectWritable(true) 构造文件系统,实际观察到 delete 返回成功且 Alice 文件消失。探针仅位于本地隔离审查副本,未修改本 PR。未运行全仓 verify。本 head 与本次 main 可干净合并。

@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ningmao-hlyz

ningmao-hlyz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

确认,别名能绕过祖先判定。project/box/workspace 旁建 project/alias -> project,用 projectWritable(true) 复现:delete(alias/box) 返回成功,alice 的 MEMORY.md 被删掉。

顺着这条线还找到一个更大的口子:同一个别名用在文件路径上时,绝对路径的拼写落在工作区外,命名空间检查根本没跑,工程层直接放行。实测 read/exists/downloadFiles/grep 能拿到 alice 的 MEMORY.md,edit 把内容改成 pwned,move 把文件搬进 bob 的目录。现在绝对路径也按落盘位置判定,落到工作区根下就走和相对键同一套 own-namespace 规则。

祖先判定按你给的方向改成比较 realPath。另外 move 之前压根没走到工程层:ProjectAwareOverlay.move 直接调 super,工程内绝对路径的移动由工作区层执行,那层没有隐藏边界,所以不带别名也能把整个 box 移走。现在两端都是工程路径的移动改走 projectFs。

回归两条:aliasedAncestor_cannotDeleteOrMoveTheHiddenSubtree(删除、移动被拒,文件仍在,删 alias 链接本身仍成功),aliasedAbsolutePath_cannotReachAnotherNamespace(两种 overlay 下 read/exists/download/grep 为空、edit 不改内容、move 不搬文件)。还原对应修复后各自变红。

验证:harness 模块 1837 用例,0 失败 / 39 skip;spotless 通过。head: 042f0a8。

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 2 times, most recently from a35141c to 042f0a8 Compare November 16, 2026 10:02

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 head 042f0a8,验证基线为本次 fetch 的 main@5a7e8e533;两者可干净合并。

此前的 ripgrep glob 字面量转义、返回路径复核及别名祖先物理路径校验已补齐。但绝对路径指向工作区祖先时,调用仍可经 workspace upper 层绕过项目层保护,实际复现了跨用户内容泄露及递归删除,建议先修复下方两处 P1。

验证范围:在隔离的最新 main + PR 合并快照上,LocalFilesystemProjectEnumerationBoundaryTest 与 LocalFilesystemUserIsolationExampleTest 共 20 项测试通过、无跳过;另用公开 LocalFilesystemSpec 构造独立探针,确认下述泄露和删除行为。探针运行时跳过格式检查,移除临时探针后单独运行 Spotless 通过;git diff --check 通过。未运行全仓 verify。探针未提交到本 PR。

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch from 9561f13 to 4e96637 Compare November 20, 2026 14:48
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch 10 times, most recently from 4fcd42f to ab9773d Compare November 20, 2026 19:54
The guard only reached the layers that excluded the root, so anything routed
above it walked in: grep, glob, ls and delete read or removed a sibling's
files through a link, a junction, an 8.3 short name or an absolute ancestor,
and one caller could unlink another namespace's link entry.

Every layer now keeps its guarded roots as a single set, spelled and resolved,
with the bound carried per root: HIDDEN loses the content, REFUSED closes the
way in from above while the layer that owns the subtree still reads inside.
A walk scope resolves its root's position once, so an entry that reaches a
guarded root only through an alias is recognised at any depth instead of by
the file name it happens to keep, and a walk that starts inside such a path
answers empty before a shelled-out search can look at it.

The overlay keeps its routing rules but gains the spellings it dropped: an
absolute path naming the workspace root or the caller's namespace root now
resolves to that root instead of falling into the project view, and an absolute
path that reaches the workspace only through a link is answered by the project
view, which hides the subtree, instead of surfacing a namespace error. A path
that lands in the caller's own namespace keeps the workspace view, so a link
into one's own files stays readable. Physical resolution moved to
FilesystemUtils so both layers share it.

Reads also had no way to see what the overlay writes: with namespaces active a
non-workspace write landed under the caller's project namespace, while every
read looked at the unnamespaced project, so exists, read, ls, grep and glob all
reported the file missing -- a success the caller could never observe. Reads now
check the workspace, then the project write layer, then the shared project, and
leave an absolute project path to the project layers: the workspace layer used
to answer for files above its own root under a "../" spelling, so the same file
came back twice under two keys.

Listing ops also disagreed with the read ops about a path a layer refuses: the
overlay let the refusal escape, so a sibling's absolute path listed as a
SecurityException while the same path read as absent, and the plain overlay did
that where the project-writable one answered empty. Enumeration now treats a
layer that refuses the path as contributing nothing, which is what read, exists
and grep already did.

Walks also disagreed with resolution about where an entry sits. A refused root
closed itself for the layer that owns it, so a caller whose namespace list is
empty -- the AGENT and GLOBAL scopes -- listed nothing while reading the same
key still worked. A directory alias that is not a symbolic link, such as a
Windows junction, passed the link check and was walked into, so a sibling's
names showed up in listings that would refuse to read them. A refused root now
closes only from above, and an entry inside the layer yet outside the caller's
namespace is skipped however the walk reached it. A refused root also stays walkable for
the layer rooted in it when the deployment spells that root through an alias, since the
refusal belongs to the layer that lives there, not to the spelling. A link to an ancestor
could also be deleted but not moved: a moving link carries nothing, and the directory flag
is now read without following it.

The classifier and the router also read spellings differently: ./MEMORY.md was
workspace metadata to one and a project key to the other, so the write landed in
the project layer while the read found it there. Keys are normalized the same
way in both. Finally, an alias may no longer carry a spelling the path policy
excludes into a place the policy allows.

Guarding is a path model, and the class doc now says where that ends: a hard link is a second
directory entry for the same file, not a pointer, so it is invisible to a resolution-based check,
and is documented as outside the boundary rather than half-detected.

A layered write could also leave the caller reading a version nobody else sees. Reads ask the
workspace layer first, so a project write under a key the workspace already holds would succeed
and leave the caller reading the other file. That write, its edit, an upload and a move are now
refused, naming the workspace copy with its stamp and size; absolute spellings are exempt,
because there the workspace layer answers only through the shared path policy. Deleting the key
removes the workspace copy first, so the refusal's recovery path converges.

Listings merged on the raw spelling, which the layers do not agree on -- a virtual layer reports
/src/ and a rooted one src/ -- so the same entry appeared twice and the upper copy never took
precedence. Merges now key on a normalized entry. Search resolves each directory once per search
instead of once per reported line.

The dev filesystem guide notes the shadowed project write and that the shell and hard links sit
outside the boundary; the 2.0 snapshot is left to the release it documents.

An alias check compared a resolved path against the path policy's configured roots. On Windows a
short-name spelling resolves to a different, longer form, so that comparison failed and the
request fell through to the unconditional policy branch, skipping the namespace check and reading
a sibling's file through the alias. The branch now checks the caller's spelling against the policy
and uses the resolved path only to decide which layer owns the destination.
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch from ab9773d to a199ec7 Compare November 20, 2026 21:56

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢补充各层的边界处理和回归测试。复审 537fa25 后,还有两处需要调整。

  1. [P1] 搜索隔离。 在 macOS 上,PR 自带的 LocalFilesystemProjectEnumerationBoundaryTest.absoluteAncestor_cannotBeScannedOrDeleted 在第 284 行失败:预期没有跨用户匹配,实际返回了匹配。请核对这一平台上的过滤行为。测试在第一条 grep 断言处停止,本轮没有独立确认后续删除断言。
  2. [P1] 合法相对文件名的兼容性。 在同一个项目目录中,文件名带一个前导空格的 report.txt 和 report.txt 可以同时存在。通过 ProjectAwareOverlay 读取前者,main 返回前者的内容,这个 head 却返回了后者的内容。relativeKey 调用了会 strip() 的 normalizeSeparators。请保留文件名本身的空格,并补一个两文件共存的回归用例。

本地文件系统定向测试 347 项,321 项通过、1 项失败、25 项跳过。文件名问题另外在 main 与 PR 上做了相同输入的对照验证。

…nked platforms

A file name may begin or end with a space, and normalizing separators trimmed it:
" report.txt" routed as "report.txt" and read that file instead. Keys now unify
separators and nothing else, and a test covers two such files in one directory.

Ripgrep's exclusion globs are matched against the process directory, which on
macOS resolves /var to /private/var while the search root keeps the /var
spelling, so a search started above the workspace could report a sibling's file.
Hits inside a refused root are now dropped when the search began outside it,
which makes the exclusion glob the fast path instead of the boundary.
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/namespace-path-boundaries branch from 3b482b7 to af6f330 Compare November 23, 2026 09:36

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢补上 macOS 和文件名兼容性修复。本地复审确认,之前失败的搜索隔离用例已通过,其中的递归删除和移动断言也通过。带前导空格的文件名能读回正确内容。

[P1] 同一个 delete 调用升级后会删除另一个副本。 在 projectWritable(true) 下,当项目和工作区有同名文件时,当前 main 的 ProjectAwareOverlay.delete 优先删除项目副本。这个 PR 的 ProjectWriteShadowTest.delete_removesTheWorkspaceCopyFirstSoTheWriteCanProceed 确认了新行为:同一个相对路径现在会删除工作区副本、保留项目副本并返回成功。已有调用方升级后因此可能意外丢失工作区里的修改。请保留现有删除路由,让本次 PR 聚焦命名空间隔离。

Delete still removes the project copy first when the key exists there and only
falls back to the workspace layer when the project has nothing. Restoring that
route keeps this PR's behavior change inside namespace isolation: callers that
delete a key with a same-named workspace copy keep losing the project copy, not
the workspace one.

The shadow refusal no longer tells the caller to delete the workspace copy
first, because delete does not do that anymore. It now states that the project
copy stays shadowed until that copy is removed.
@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

删除语义回到原样,这个 PR 只做命名空间隔离。

xzxiaoshan added a commit that referenced this pull request Nov 26, 2026
…#4435)

## Background

Swept the last 125 PRs (#4434→#4239), every single-OS-failed CI run
since 2026-11-19 and the main-branch push runs for `mvn -B -T1C clean
verify` failures (one build OS red and the other green on the same
commit = flake suspect). Four test classes still fail on current main:
three fail on windows-latest only, and the fourth sits at its deadline
on both OSes. All fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `HarnessAgentStructuredOutputStreamEventsTest` | #4296, #4349, #4071,
main run 44879286932 (2026-11-20 to 11-23), all windows-latest |
`streamEvents(...).block(10s)` timed out at 10.2-11.3s per call; the
class takes 3.7-9.6s on windows-latest when green and 1-1.5s on ubuntu |
ephemeral `InMemoryThreadJournalStore` in the three workspace-backed
tests (the fourth already used one) |
| `HarnessAgentOverflowRecoveryTest` | #4042, #4426 (2026-11-26), both
windows-latest; the journal rows were added by #4399 on 11-25 | row
`[3]` (journal=true) crossed `block(30s)` at 36.3-38.1s and row `[4]`
passed with 33.8s; the same rows take 0.4-1.3s on ubuntu, and main's own
run 45595615922 needed 61s for the class on windows-latest | ephemeral
`InMemoryThreadJournalStore` in `newAgent` |
| `DashScopeMultiModalEmbeddingTest` | #4413 (2026-11-25),
windows-latest | the first SDK request in the fork hit the 5s latch
(7.29s elapsed); the class takes 1.4-4.2s on windows-latest even when
green | first-request latch 5s→15s |
| `AnthropicAutoConfigurationTest` | #2363, run 45137197507
(2026-11-23), windows-latest | the first gateway test crossed
`block(10s)` at 15.66s; the other three take under 1s, and this one
already takes 5-11s on windows-latest and 9-12s on ubuntu when green |
block 10s→30s |

The first two share one cause: since #4154 the default workspace journal
is `SqliteJournalStorage` on Windows, which opens a JDBC connection per
storage operation and commits every CAS as a durable transaction (DELETE
journal, synchronous EXTRA). A journaled turn issues about 20 such
writes at roughly 8ms each on a fast local disk. Neither class asserts
journal persistence, so they now use the ephemeral backend the
repository already documents for tests. Locally on Windows the
overflow-recovery class dropped from 17.9s to 5.6s and the
structured-output class from 3.2s to 1.6s.

## Constraint compliance

- Happy path zero cost: the journal swap removes work, the two
relaxations only move failure deadlines, and no sleeps or weakened
assertions were added.
- Structural hardening first: the journal swap is structural. For the
two cold-start waits the structural alternative, a warm-up request
before the timed section, would add a request to every run, so the
deadline was relaxed instead.
- Minimal widening anchored to measured data: each relaxation is 3x the
deadline that was crossed, and every comment cites its victims and
measured values.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`WorkerRuntimeTest.saturatedStartsDoNotBlockRecoveryAndDrainPreservesActiveLeases`
(#4294, windows-latest, 36.19s at the `renewed` latch): with the test's
4s worker lease a heartbeat delayed by more than 2.7s finds the lease
already expired and fails with `Worker lease lost` instead of arriving
late, so widening the latch (as #4274 did to 30s) cannot help. That
latch is the only place asserting the runtime renews leases, and a
longer lease would delay the first heartbeat by lease/3, so the fix
needs a design decision.
-
`SubagentFactoryDeclarationTest.declaredFactory_persistSessionIsolatesUsers`
(main run 45172445003, 2026-11-23, 31.45s) and
`ChatControllerTest.httpUsesExplicitCreationAndTargetedIdempotentControls`
(main run 44566773929 and #4255, both 2026-11-19): no recurrence since.
- Two windows-latest hangs that ended at the 2h job timeout:
`AgentSpawnToolPermissionTest` (#4305, run 44760439728) and
`AgentSpawnToolPlanModeTest` (main run 45739005058 on the current head).
Both classes wait with unbounded `.block()`; the root cause is not
established, and the 30-minute Surefire fork timeout in the root pom did
not end either run.
- The cost of the Windows default journal itself (one JDBC connection
and one durable transaction per storage operation) is a production
concern that deserves its own `src/main` change.
- Already fixed upstream, victims predate the fix:
`JevEvidenceProcessorTest` (13 runs, fixed by #4346),
`ChatSessionsTest`, `RocketMqExecutionTest` and `AgentScopeAdapterTest`
(fixed by #4274).
@juruoO-o

juruoO-o commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

复核了删除路由,项目和工作区同名时已恢复优先删除项目副本,先前这一条阻塞已解决。当前分支与 main 有冲突,请同步后再请求最终评审,尤其留意 overlay 删除路由和命名空间隔离。

Conflicts: only the import block in AbstractFilesystem.java; main added
Supplier (readSnapshot from agentscope-ai#4522), this branch adds Optional (stat). Kept
both.
@ningmao-hlyz

ningmao-hlyz commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@juruoO-o 已同步 main(e4b07aeb),CI 全绿,冲突解决了。只有 AbstractFilesystem.java 的 import 块一处:main 的 #4522 加了 Supplier,这条分支加了 Optional,两个都留。

按你提醒复看了 overlay 删除路由和命名空间隔离:ProjectAwareOverlay.delete 仍是项目副本优先,normalizeSeparators 保留文件名的前后空格;#4522 对 overlay 只加了 readSnapshot,不接路径,隔离面没有新入口。另外补测了命名空间内的符号链接,文件型和目录型都试了,read/ls/grep/glob/download 都碰不到兄弟命名空间。

本地 Windows / Java 17:三套边界用例 68 项全过,harness 全模块 2,385 项 0 失败 52 跳过。麻烦最终看一下。

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed namespace isolation and confirmed that deletion by relative path still removes the project copy first. The integration preserved both imports and the Ubuntu and Windows builds passed.

@juruoO-o
juruoO-o merged commit 634fe8d into agentscope-ai:main Dec 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Blank and relative paths in the file tools enumerate other users' namespaces

5 participants