Skip to content

OpenShell: harden mirror sync boundaries - #57693

Merged
jacobtomlinson merged 4 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-100
Mar 30, 2026
Merged

jacobtomlinson merged 4 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-100

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • hardens OpenShell mirror sync so sandbox downloads no longer materialize symlinks on the host
  • stages uploads through a symlink-free snapshot and preserves trusted host-only directories during mirror sync

Changes

  • replaced the direct fs.cp(..., dereference: false) mirror copy with a recursive file-and-directory copy that drops symlinks and other special entries
  • expanded the mirror exclusion set to preserve hooks, git-hooks, and .git on the host during sandbox downloads
  • staged workspace uploads through a temporary directory and prevented syncLocalPathToRemote from mirroring host symlinks back into the sandbox
  • added filesystem regression tests covering excluded directories plus skipped symlinks on both download and upload staging paths

Validation

  • Ran pnpm test -- extensions/openshell/src/mirror.test.ts
  • Ran pnpm test -- extensions/openshell/src/openshell-core.test.ts
  • Ran pnpm build
  • Ran local agentic review with claude -p '/review' and addressed the actionable feedback

Notes

  • Residual risk or follow-up: this validates the local mirror helpers and build path; it does not exercise a live OpenShell CLI end-to-end in this environment

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Mar 30, 2026
@greptile-apps

greptile-apps Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens the OpenShell mirror sync boundary in two important ways: (1) the sandbox-to-host download path now strips symlinks using a recursive copyTreeWithoutSymlinks helper instead of fs.cp({dereference: false}), which previously allowed a sandbox process to materialise arbitrary host symlinks; and (2) the host-to-sandbox upload path now stages content through a symlink-free temp directory before invoking the CLI uploader. The exclusion list protecting trusted host directories is also expanded from ["hooks"] to ["hooks", "git-hooks", ".git"].

The implementation is logically sound and the security rationale is clear. The new tests cover excluded directories, symlink skipping on both directions, and the stageDirectoryContents helper. Two minor style observations:

  • The stageDirectoryContents test case lives inside describe(\"replaceDirectoryContents\") even though it exercises a different function — a small organisational mismatch that makes test output slightly misleading.
  • copyTreeWithoutSymlinks traverses directory entries sequentially with for...of + await; using Promise.all (already done in the deletion phase of replaceDirectoryContents) would parallelize the I/O on large workspaces.

Confidence Score: 5/5

Safe to merge — no logic or security defects found; all remaining findings are P2 style suggestions.

The security hardening is correctly implemented: symlinks are reliably dropped via lstat checks before any copy or upload, excluded dirs are preserved atomically, and the new tests validate all added paths. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
extensions/openshell/src/mirror.ts Replaces fs.cp with a custom symlink-stripping recursive copy helper; adds stageDirectoryContents and DEFAULT_OPEN_SHELL_MIRROR_EXCLUDE_DIRS exports.
extensions/openshell/src/backend.ts Expands download exclusion list to include git-hooks and .git; adds symlink guard in syncLocalPathToRemote; routes uploadPathToRemote through a staged temp dir.
extensions/openshell/src/mirror.test.ts Adds tests for default excluded dirs, symlink skipping on download, and symlink-free staging on upload; all housed inside the existing replaceDirectoryContents describe block.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/openshell/src/mirror.test.ts
Line: 149

Comment:
**Test grouped under wrong `describe` block**

The `stageDirectoryContents` test (and its siblings added by this PR) are placed inside `describe("replaceDirectoryContents")`, but the last test case exercises `stageDirectoryContents`, a different exported function. This makes it harder to find failures and misleads the test reporter output. Consider nesting it in its own `describe("stageDirectoryContents")` block.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/openshell/src/mirror.ts
Line: 23-29

Comment:
**Sequential directory traversal may be slower for large trees**

`copyTreeWithoutSymlinks` processes each directory entry one-at-a-time via `for...of` + `await`. For directories with many entries this serializes all the `lstat`/`copyFile` I/O calls. Switching to `Promise.all` over the entries (as the deletion phase of `replaceDirectoryContents` already does) would parallelize the I/O and speed up mirror sync on large workspaces.

```suggestion
    const entries = await fs.readdir(params.sourcePath);
    await Promise.all(
      entries.map((entry) =>
        copyTreeWithoutSymlinks({
          sourcePath: path.join(params.sourcePath, entry),
          targetPath: path.join(params.targetPath, entry),
        }),
      ),
    );
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "OpenShell: harden mirror sync boundaries" | Re-trigger Greptile

Comment thread extensions/openshell/src/mirror.test.ts Resolved
Comment thread extensions/openshell/src/mirror.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7310780496

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/openshell/src/mirror.ts Resolved
Comment thread extensions/openshell/src/mirror.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b817eb817a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/openshell/src/mirror.ts Resolved
@jacobtomlinson
jacobtomlinson merged commit 3b9dab0 into openclaw:main Mar 30, 2026
8 checks passed
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
Tardisyuan pushed a commit to Tardisyuan/openclaw that referenced this pull request Apr 30, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
* OpenShell: harden mirror sync boundaries

* OpenShell: polish mirror hardening tests

* OpenShell: preserve trusted mirror symlinks

* OpenShell: bound mirror fs work globally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant