Skip to content

[Bug]: Memory reads fall back to un-namespaced workspace paths, letting one user read another's MEMORY.md #4052

Closed

Description

@ningmao-hlyz

Summary

With the default IsolationScope.USER, MEMORY.md is written under the caller's
namespace (<workspace>/<userId>/MEMORY.md) — but the read path falls back out of
it. WorkspaceManager.readWithOverride asks the filesystem first (which applies the
namespace) and, on a miss, falls back to workspace.resolve(relativePath), the
un-namespaced path.

memory_get is registered by default (HarnessAgent:3037) and its containment check
(MemoryGetTool:60) validates the bare relative path, so a path that names another
user's directory passes containment. Reproduced on main (674fea68):

Call (as bob) Result
memory_get("alice/MEMORY.md") SUCCESS, returns alice's content
memory_get("./alice/MEMORY.md") same
memory_get("../alice/MEMORY.md") rejected (.. is validated)
any read while a root-level MEMORY.md exists every identified caller is served it

The root-level case is the upgrade path: a workspace written before namespace
scoping keeps its MEMORY.md at the root. It is now served to every user, while
memory_search does not list it — the read and search surfaces disagree.

To Reproduce

try (HarnessAgent agent = HarnessAgent.builder()
        .name("assistant").model(stubModel).workspace(workspace).build()) {
    agent.getWorkspaceManager().writeUtf8WorkspaceRelative(
            RuntimeContext.builder().userId("alice").build(), "MEMORY.md", "alice-private");

    ToolResultBlock r = new MemoryGetTool(agent.getWorkspaceManager())
            .memoryGet(RuntimeContext.builder().userId("bob").build(), "alice/MEMORY.md", 1, 5);
    // → SUCCESS, "alice-private"
}

Expected: file not found, and a root-level leftover is not served to an
identified caller.

Actual: alice's file is returned to bob.

Why #3292 / #3261 do not cover this

#3292 makes absolute keys respect the namespace boundary. This path is relative:
alice/MEMORY.md is prefixed to bob/alice/MEMORY.md by the filesystem layer, which
misses, and the fallback then reads the un-namespaced workspace/alice/MEMORY.md.
The boundary check never runs on the fallback. #3253 and #3378 cover root
enumeration and .. segments respectively; neither touches this fallback.

Scope

readMemoryFileUtf8 / readMemoryMd back the prompt injection
(WorkspaceContextMiddleware), MemoryConsolidator, MemoryFlushManager, and both
memory tools. readManagedWorkspaceFileUtf8 shares the fallback but its callers pass
build-time paths, so it is not reachable from the model.

AGENTS.md and knowledge/ are shared agent configuration and must keep resolving at
the workspace root (#2501, #2687). MEMORY.md and the daily ledgers are per-identity
runtime data and cannot share that rule.

Suggested fix

Anchor the memory-family fallback to the caller's namespace
(resolveRuntimeDataPath), keep the root read only when the context carries no
namespace at all, and validate memory_get against the resolved path. A root-level
leftover should be reported once so an operator knows to move it.

Activity

  1. added 8 commits that reference this issue on Nov 8, 2026
    85a05ca
    616ddbc
    28e4491
    dc5ef97
    1321095
    94b40a8
    f0962d5
    9c62673
  2. added a commit that references this issue on Nov 11, 2026
    e5dd389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions