Skip to content

fix(memory): reject reads outside a replaced authorized directory - #156222

Merged
steipete merged 1 commit into
mainfrom
codex/fs-safe-memory-read-20260923
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fs-safe-memory-read-20260923

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #154370

What Problem This Solves

Fixes memory reads returning contents outside an authorized directory when that directory is replaced between path admission and the actual read.

User Impact

Memory reads and transient retries stay bound to the admitted filesystem root. Existing contained workspace aliases, strict extra-directory rules, hardlinks, literal filenames, Markdown/glob restrictions, file-size behavior, and missing-file versus I/O-error results remain supported.

Why This Change Was Made

The memory reader now retains the existing fs-safe Root through the content read and retry, replacing separate path checks followed by an unrelated absolute-path read. This removes duplicate containment helpers without changing configuration, stored formats, or public memory APIs. The existing memory_get and remote-worker routes continue to call the same reader.

Evidence

  • Two real directory-substitution cases returned outside contents on the original implementation and now refuse the substituted data. Existing compatibility controls also passed on the original source.
  • Final focused proof passed 40 cases in 73.022 seconds. The changed reader suite passed all 15 cases with node scripts/run-vitest.mjs packages/memory-host-sdk/src/host/read-file.test.ts --maxWorkers=1 --reporter=verbose in 59.985 seconds wall time. Cold preparation differs between runs; no speed comparison is claimed.
  • Coverage includes contained workspace aliases, rejected extra-root aliases, hardlinks, literal ~, Markdown/glob admission, transient EAGAIN retries, propagated EIO, and missing/error distinctions.
  • All selected check components passed across the initial runs and targeted lint corrections, including core and all 25 test type graphs, dead exports, formatting, and the remaining guards. The final ten-command recovery run passed in 583.501 seconds; the original failing check command is not represented as a pass.
  • Earlier review findings about retry and I/O propagation were fixed. The final review's Markdown-widening claim was rejected after source inspection: matchesDirectory still requires .md, its directory branch requires that predicate, and the retained note.txt rejection case passes. Raw review findings were preserved; there are no accepted actionable findings. The final lint edit only omitted an identical default void type argument.
  • Proof used synthetic local files on macOS. No Windows or live-Gateway execution is claimed.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 23, 2026 05:36
@steipete

Copy link
Copy Markdown
Contributor Author

CI test cost for this exact head: run 35823086271 passed. In checks-node-compact-small-10, all 15 reader cases passed. Their logged case durations total 155 ms, including 2 ms for each directory-substitution regression; this is aggregate case time, not standalone file wall time. The containing 271-file shard took 33.34 seconds in Vitest and 36.22 seconds wrapper wall time (5,180 passed, 1 skipped).

The standalone local reader run remains the 59.985-second wall measurement recorded in the PR body; these measurements include different preparation and suite grouping, so no speed comparison is claimed.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The earlier exact-head review completed successfully in workflow 35823200396, but publishing its result hit a GitHub rate limit. Its saved artifact was accepted into the publication queue and has remained unpublished for more than 40 minutes. The original result and queue receipt remain retained for reconciliation; this is one recovery request through the normal revision-fenced workflow.

The head is unchanged at 65c5673f726354cfa7d12b2dc1795fbf3dbf1018, and exact-head CI is green. Precise reader CI timings are recorded in the earlier evidence comment, including the distinction between aggregate case time and standalone wall time.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 23, 2026, 2:36 AM ET / 06:36 UTC.

ClawSweeper review

What this changes

The memory reader retains its authorized filesystem root through content reads and retries, preventing directory replacement from redirecting reads outside that root.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful, focused fix: current main and the latest release still separate path admission from content reading. No actionable correctness or security regression was found.

Priority: P2
Reviewed head: 65c5673f726354cfa7d12b2dc1795fbf3dbf1018

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant filesystem evidence, preserved compatibility controls, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduced change: Reviewed the merge-base-to-head patch and complete changed reader, filesystem facade, and reader tests. The Root is created outside the retry callback and reused for every content-read attempt; Markdown/glob admission and result shaping remain in their existing owners.
Still necessary on current main: Fetched main still resolves the workspace path separately and later calls readRegularFile with an absolute pathname. It does not retain the admitted Root through the content read.
Latest release retains the old read path: The supplied latest release, v2026.9.5, also contains workspaceRoot.resolve followed by the separate readRegularFile call. No shipped replacement for this fix was established.
Findings None None.
Security None None.

How this fits together

Memory Core sends memory_get requests and remote workspace reads through the shared memory reader. It checks workspace and configured extra-path permissions, reads the permitted file, and returns a bounded excerpt.

flowchart TD
  A[Memory read request] --> B[Workspace and extra-path rules]
  B --> C[Retained filesystem root]
  C --> D[Identity and containment checks]
  D --> E[Content read and transient retry]
  E --> D
  E --> F[Bounded memory excerpt]
  D --> G[Missing result or read error]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -29, Tests +149. Total +120 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 79 108 -29
Tests 1 151 2 +149
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 230 110 +120

Review metrics

Metric Value Why it matters
Reader test cost 15 cases: 155 ms aggregate CI case time; 59.985 s standalone local wall time The supplied measurements distinguish fast regression execution from preparation and suite overhead.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/memory-host-sdk/src/host/read-file.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/read-file.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep admission and content reading under one retained filesystem root while preserving existing memory-path and error contracts.

Do we have a high-confidence way to reproduce the issue?

Yes: replace an admitted workspace or extra directory before the content-read callback. Current main still performs a separate absolute-path read; the contributor reports before/after filesystem reproduction, while this review remained read-only.

Is this the best way to solve the issue?

Yes: using the existing fs-safe Root removes the admission/read split without introducing a competing containment implementation or changing public memory APIs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b568ad2e87ae.

Labels

Label changes:

  • add P2: This fixes a bounded memory-read containment race without evidence of an active widespread outage or exploit.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.

Label justifications:

  • P2: This fixes a bounded memory-read containment race without evidence of an active widespread outage or exploit.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported macOS real-filesystem runs exercise the production reader with allowed files and substituted unauthorized directories, showing outside contents before the fix and rejection afterward. Source inspection confirms retained-root checks through final descriptor admission and retries. CI-log retrieval was blocked by the review network; no Windows or live-Gateway coverage is claimed. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head patch and complete changed reader, filesystem facade, and reader tests. The Root is created outside the retry callback and reused for every content-read attempt; Markdown/glob admission and result shaping remain in their existing owners. (packages/memory-host-sdk/src/host/read-file.ts:67, 65c5673f7263)
  • Still necessary on current main: Fetched main still resolves the workspace path separately and later calls readRegularFile with an absolute pathname. It does not retain the admitted Root through the content read. (packages/memory-host-sdk/src/host/read-file.ts, b568ad2e87ae)
  • Latest release retains the old read path: The supplied latest release, v2026.9.5, also contains workspaceRoot.resolve followed by the separate readRegularFile call. No shipped replacement for this fix was established. (packages/memory-host-sdk/src/host/read-file.ts:174, ec9c1a13db89)
  • Dependency boundary: The changed reader imports Root through fs-utils, which directly re-exports @openclaw/fs-safe/root; the checked-out lockfile pins version 0.18.1. This establishes the fs-safe dependency contract as relevant; no Codex dependency signal applies. (packages/memory-host-sdk/src/host/fs-utils.ts:2, 65c5673f7263)
  • Final read authority: Verified repository ownership and resolved v0.18.1 to this dependency commit. Root reading resolves against retained identity, admits the opened descriptor through root/file/root identity checks, then reads that descriptor and closes it. Replacement produces path-mismatch instead of returning substituted contents. (src/root-read-admission.ts, fb70418d8cbd)
  • Real filesystem proof and compatibility: The captured PR body reports macOS runs where both directory-substitution cases returned outside contents before the fix and refused them afterward. Inspected tests call the production reader and real filesystem operations, injecting substitution at the retry boundary. Controls cover contained workspace aliases, strict extra roots, hardlinks exceeding 16 MiB, literal tilde paths, Markdown/glob restrictions, EAGAIN recovery, and EIO propagation. The supplied evidence reports 40 focused cases and all 15 reader cases passing; Windows and live-Gateway execution are explicitly not claimed. (packages/memory-host-sdk/src/host/read-file.test.ts:106, 65c5673f7263)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SebTardif: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 6619a0e into main Sep 23, 2026
231 checks passed
@steipete
steipete deleted the codex/fs-safe-memory-read-20260923 branch September 23, 2026 14:36
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer disposition: the data-model classification is not applicable to this diff. It changes only file admission/read ownership, error handling, and reader tests. There are no schema, embedding metadata, serialization, write, migration, or retention changes, and no operator-state conversion is needed. Existing Markdown files and configured extra paths remain the input. Compatibility controls cover contained workspace aliases, strict extra roots, hardlinks, literal filenames, Markdown/glob restrictions, unlimited prior size behavior, and missing/transient/I/O-error results. The review itself confirms no stored-data contract changes and sufficient real-filesystem proof.

The root-replacement regressions failed on the original implementation and passed on the candidate; the focused 40-case proof and exact-head CI passed. There are no accepted actionable review findings.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…enclaw#156222)

Related: openclaw#154370

## What Problem This Solves

Fixes memory reads returning contents outside an authorized directory when that directory is replaced between path admission and the actual read.

## User Impact

Memory reads and transient retries stay bound to the admitted filesystem root. Existing contained workspace aliases, strict extra-directory rules, hardlinks, literal filenames, Markdown/glob restrictions, file-size behavior, and missing-file versus I/O-error results remain supported.

## Why This Change Was Made

The memory reader now retains the existing fs-safe Root through the content read and retry, replacing separate path checks followed by an unrelated absolute-path read. This removes duplicate containment helpers without changing configuration, stored formats, or public memory APIs. The existing `memory_get` and remote-worker routes continue to call the same reader.

## Evidence

- Two real directory-substitution cases returned outside contents on the original implementation and now refuse the substituted data. Existing compatibility controls also passed on the original source.
- Final focused proof passed 40 cases in 73.022 seconds. The changed reader suite passed all 15 cases with `node scripts/run-vitest.mjs packages/memory-host-sdk/src/host/read-file.test.ts --maxWorkers=1 --reporter=verbose` in 59.985 seconds wall time. Cold preparation differs between runs; no speed comparison is claimed.
- Coverage includes contained workspace aliases, rejected extra-root aliases, hardlinks, literal `~`, Markdown/glob admission, transient `EAGAIN` retries, propagated `EIO`, and missing/error distinctions.
- All selected check components passed across the initial runs and targeted lint corrections, including core and all 25 test type graphs, dead exports, formatting, and the remaining guards. The final ten-command recovery run passed in 583.501 seconds; the original failing check command is not represented as a pass.
- Earlier review findings about retry and I/O propagation were fixed. The final review's Markdown-widening claim was rejected after source inspection: `matchesDirectory` still requires `.md`, its directory branch requires that predicate, and the retained `note.txt` rejection case passes. Raw review findings were preserved; there are no accepted actionable findings. The final lint edit only omitted an identical default `void` type argument.
- Proof used synthetic local files on macOS. No Windows or live-Gateway execution is claimed.
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant