Skip to content

fix: sandbox write fails for existing subdirectories (mkdirp boundary check)#30610

Merged
steipete merged 2 commits intoopenclaw:mainfrom
glitch418x:fix/sandbox-write-mkdir
Mar 1, 2026
Merged

fix: sandbox write fails for existing subdirectories (mkdirp boundary check)#30610
steipete merged 2 commits intoopenclaw:mainfrom
glitch418x:fix/sandbox-write-mkdir

Conversation

@glitch418x
Copy link
Copy Markdown
Contributor

Problem

The write tool fails in sandbox mode when creating files in subdirectories:

Sandbox boundary checks failed; cannot create directories: /workspace/memory/kemik

Regression from 2026.2.26 security hardening. The mkdirp call passes a directory path through openVerifiedFileSync which only accepts files (isFile() check).

Root Cause

createSandboxWriteOperations.mkdirbridge.mkdirpassertPathSafetyopenBoundaryFileopenVerifiedFileSync:

if (!preOpenStat.isFile()) return { ok: false, reason: "validation" };

Directories fail the isFile() check, returning reason: "validation", which causes the boundary check to throw.

Fix

  • safe-open-sync.ts: Accept directories when a new allowDirectory option is set
  • boundary-file-read.ts: Pass allowDirectory through to the safe-open layer
  • fs-bridge.ts: Set allowDirectory: true when calling boundary check from mkdirp
  • Added tests for both the safe-open directory case and the fs-bridge mkdirp flow

Testing

  • New unit tests for directory boundary checks
  • New unit tests for mkdirp in sandbox mode
  • Existing sandbox security tests unaffected

Fixes #30582

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: S labels Mar 1, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 1, 2026

Greptile Summary

This PR fixes a regression from recent security hardening where mkdirp operations failed for existing subdirectories. The root cause was that boundary checks were hardcoded to only accept files, causing directory paths to fail validation.

Key Changes:

  • Added SafeOpenSyncAllowedType ("file" | "directory") to allow configurable file type validation
  • Modified openVerifiedFileSync to accept allowedTypes parameter (defaults to ["file"] for backward compatibility)
  • Updated mkdirp to pass allowedTypes: ["directory"] during boundary checks
  • Properly handled edge cases: hardlink checks and size validations now only apply to files, not directories
  • Added comprehensive test coverage for both the low-level safe-open function and high-level mkdirp flow

Security Impact:
The fix maintains all existing security boundaries - it only corrects the file type check to properly support directories when explicitly requested. All TOCTOU protections, boundary validations, and path safety checks remain intact.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is minimal, well-targeted, and properly tested. It introduces an optional parameter with a safe default, maintains all security boundaries, and includes comprehensive test coverage. The implementation correctly handles edge cases like hardlink and size checks for directories.
  • No files require special attention

Last reviewed commit: a41a812

@steipete steipete force-pushed the fix/sandbox-write-mkdir branch from a41a812 to 17cccc2 Compare March 1, 2026 21:41
@steipete steipete merged commit 3be1343 into openclaw:main Mar 1, 2026
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Mar 1, 2026

Landed via temp rebase onto main.

  • Gate: pnpm check && pnpm build && pnpm test && pnpm check:docs (local full gate blocked by unrelated baseline test failures in Ollama/Web reconnect tests); targeted regression tests passed: pnpm exec vitest run src/infra/safe-open-sync.test.ts src/agents/sandbox/fs-bridge.test.ts; docs gate passed: pnpm check:docs
  • Land commit: 17cccc2
  • Merge commit: 3be1343

Thanks @glitch418x!

ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
hanqizheng pushed a commit to hanqizheng/openclaw that referenced this pull request Mar 2, 2026
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…glitch418x)

(cherry picked from commit 3be1343)

# Conflicts:
#	CHANGELOG.md
#	src/agents/sandbox/fs-bridge.test.ts
#	src/agents/sandbox/fs-bridge.ts
#	src/infra/boundary-file-read.ts
#	src/infra/safe-open-sync.test.ts
#	src/infra/safe-open-sync.ts
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox write fails for existing subdirectories with workspaceAccess: rw (2026.2.26 regression)

2 participants