[Bug] Enumeration surfaces: relative and ..-bearing paths bypass the namespace anchor (sibling-tenant access)
Summary
Follow-up from the #3254 review (non-blocking items), covering the ..-segment escape class on the enumeration surfaces that the shared AbstractFilesystem.denotesRootPath helper does not yet close:
- Relative root-equivalent forms —
./,.., andsub/..are not classified as root spellings and reach backends raw. On a namespaced ROOTEDLocalFilesystem,applyNamespacePrefixyieldsuser-2/..andcwd.resolve("user-2/..").normalize()lands on the workspace root — the sibling-tenant listing that the #3253 tests guard against for absolute spellings. - Non-root absolute paths containing
..—ls("/alice/../bob")is forwarded raw; absolute paths bypass the namespace prefix, so the enumeration re-roots outside the caller's namespace.
denotesRootPath classifies but does not normalize, so fixing (1) alone is not enough for (2) — the enumeration surfaces (ls/grep/glob) need to normalize ./.. segments (or reject them) before delegation, consistently across CompositeFilesystem and the backends.
- Interface-level null-handling test —
CompositeFilesystem.grepforwardsnullverbatim to the default backend (its documented working-directory form); every in-tree backend honours it viadenotesRootPath, but containment depends on each new implementation remembering the convention. A contract test enumerating allAbstractFilesystemimplementations would pin it.
Scope note
All of these are pre-existing behaviours, explicitly acknowledged as non-blocking in the #3254 review ("nothing here needs a redesign — the follow-ups can be a separate PR"). #3254's javadoc wording was adjusted in that PR to claim only root-spelling closure; this issue tracks closing the remaining ..-segment class.
Suggested direction
- Extend
denotesRootPath(or addnormalizeEnumerationPathat theAbstractFilesystemlevel) to resolve./..for relative input and to strip/resolve..segments for absolute non-root input before delegation; - or reject relative/
..-bearing enumeration paths with anIllegalArgumentException, mirroring howdelete/movealready gate onvalidatePath; - plus the interface-level null contract test from (3).
Issue Evaluation
Category: bug | Status: Partially confirmed (verified against main @ addf82b89, 2.0.4-SNAPSHOT)
We reproduced the reported behaviour with an executable probe (a workspace containing user-1/ and user-2/secret.txt; no repo files were modified). The escape class is real, but the affected configuration and the mechanism differ from the report.
Confirmed
| Claim | Evidence |
|---|---|
Enumeration surfaces (ls/grep/glob) are unguarded, unlike delete/move |
validatePath (AbstractFilesystem.java:178-188) has 8 call sites, all on delete/move/upload (LocalFilesystem.java:530,559-560; CompositeFilesystem.java:465,476-477; RemoteFilesystem.java:597,615-616; BaseSandboxFilesystem.java:427,439-440) — none on the enumeration path |
Relative .. escapes a per-user namespace |
probe: ls('..') → [user-1/, user-2/], glob('**','..') → [own.txt, user-2/secret.txt] — sibling namespaces become enumerable |
applyNamespacePrefix does not touch ./.. segments |
LocalFilesystem.java:689-707: .. → user-1/..; then resolveUnrestricted (:681-687) does cwd.resolve(target).normalize() with no validation |
CompositeFilesystem.grep forwards null verbatim to the default backend |
CompositeFilesystem.java:280-282; documented contract at AbstractFilesystem.java:98 (null searches the working directory). All in-tree backends currently behave, but nothing pins it — no contract test exists |
The #3253 guards cover read/upload only, not enumeration |
LocalFilesystemModeTest.java:285-293, 314-325, 328-347, 350-369 all target read/upload; there is no ls/grep/glob traversal case anywhere under agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/ |
Corrections
AbstractFilesystem.denotesRootPathdoes not exist in this tree. Root classification is inlined per call site:"/".equals(path)/".".equals(path)atCompositeFilesystem.java:199,280,343andLocalFilesystem.java:421, plusRemoteFilesystem.normalizePath(:720-723). So "extenddenotesRootPath" is not an actionable option; "introduce a shared helper" is.- A namespaced ROOTED
LocalFilesystemdoes not leak.resolveRootedcallsAbstractFilesystem.validatePath(effectiveKey)as its first statement (LocalFilesystem.java:633-634), so thecwd.resolve("user-2/..").normalize()path you describe is never reached — probe:[ROOTED] ls('..') threw IllegalArgumentException. The reachable escape is UNRESTRICTED + namespace, which is exactly the default backend ofRemoteFilesystemSpecwhensharedLocalWorkspace=false(RemoteFilesystemSpec.java:244-247, wired viaHarnessAgent.java:2428,2438,2499). The report does not mention that configuration, and it is what makes this worth fixing. ./andsub/..are not escapes. Both normalize back inside the namespace (probe:[UNRES] ls('sub/..')→[own.txt],[ROOTED] ls('./')→[own.txt]). Rejecting every "relative /..-bearing" path as the suggested direction implies would break legitimate relative usage; only..segments that move the resolved result outside the anchor need handling.- Absolute paths bypassing the namespace prefix is intentional and already pinned, not a defect: see the comment at
LocalFilesystem.java:693-700and the testsrooted_absolutePathNotCorruptedByNamespace(LocalFilesystemModeTest.java:149-163) /rooted_leadingSlashWithNamespace(:250-265). Under UNRESTRICTED any absolute path can enumerate the host — that is the documented escape hatch (workspace/LocalFsMode.java) — sols("/alice/../bob")is one instance of a by-design property; normalizing..inside it would not restore containment. - "every in-tree backend honours
nullviadenotesRootPath" — each backend handlesnullits own way (LocalFilesystem.java:397→".";RemoteFilesystem.java:335withnormalizePath:720-723→"/";BaseSandboxFilesystem.java:334,381;OverlayFilesystem.java:196-199/ProjectAwareOverlay.java:224-228/BakedContextFilesystem.java:77-79pass it through). Notably the sandboxlsdoes not honour it:nullreachesFilesystemUtils.shellQuote(:101-106) and becomes'', i.e. a degraded failure rather than a working-directory search. The contract test you propose should pinlsas well asgrep. - Side observation: in ROOTED a traversal attempt raises
IllegalArgumentException(:634), whileLocalFilesystem.greponly catchesSecurityException(:396-400), so the exception propagates raw throughCompositeFilesystemto the tool layer instead of surfacing as a typed tool error. Worth folding into the same cleanup.
Severity: high. Cross-tenant enumeration of sibling namespaces (directory names, and file paths via glob) under the default distributed wiring. Not critical: delete/move stay guarded, and local single-user setups default to ROOTED (LocalFilesystemSpec.java:61), which is already safe. Whether read/write also cross the boundary is a strong inference rather than a measured fact — they share resolvePath, but we did not execute that case.
Fix direction we would propose
- Primary: tighten
LocalFilesystem.resolveUnrestricted(:681-687) for relative input whose normalized result leaves the anchor, mirroringresolveSandboxed:611-613in both condition and exception type. One call site covers ls/grep/glob/read/write/edit/upload/download/exists (all go throughresolvePath), keeps absolute pass-through intact (changing it would break the contracts pinned in correction 4), and matches the documented UNRESTRICTED semantics "relative paths anchor to rootDir" — a relative..already contradicts that wording today. - Secondary: add the interface-level contract test you suggest, parameterized over all in-tree
AbstractFilesystemimplementations, pinning (a)grep(null)/ls(null)search the working directory only and (b)ls/grep/globwith..stay within the namespace. Candidate cases inLocalFilesystemModeTest:unrestricted_namespaced_lsDotDotCannotEscapeUserNamespace,unrestricted_namespaced_globDotDotCannotEscapeUserNamespace,unrestricted_namespaced_dotSlashAndSubDotDotStayInNamespace; plusRemoteFilesystemSpecTest.defaultBackend_namespaced_lsDotDotDoesNotListSiblingNamespacesto pin the production default end-to-end.
Next step
We are not opening a PR unconditionally here. @aiyili if you plan to send this yourself, say so and we will review it; otherwise tell us which fix location you prefer (mode-level in resolveUnrestricted vs a shared enumeration helper on AbstractFilesystem) and we will turn it into a concrete proposal. We would also narrow the scope note to the UNRESTRICTED + namespace wiring per corrections 2–4.
Automated evaluation by github-manager-bot
Hi, this is the follow-up I filed from the #3254 review — taking it myself. Plan: resolve ./.. segments for relative input and ..-bearing absolute paths on the enumeration surfaces (shared helper), plus the interface-level null-handling contract test enumerating all AbstractFilesystem implementations. PR coming shortly.