Skip to content

fix(browser): resolve symlink paths in upload validation - #23131

Closed
PinoHouse wants to merge 1 commit into
openclaw:mainfrom
PinoHouse:fix/browser-upload-symlink-path
Closed

PinoHouse wants to merge 1 commit into
openclaw:mainfrom
PinoHouse:fix/browser-upload-symlink-path

Conversation

@PinoHouse

@PinoHouse PinoHouse commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes browser upload rejecting valid files inside /tmp/openclaw/uploads on macOS ([Bug]: browser upload rejects valid files inside /tmp/openclaw/uploads #23107)
  • On macOS, /tmp is a symlink to /private/tmp. When the CLI resolves paths via fs.realpath and sends them to the gateway, resolvePathWithinRoot() compares /private/tmp/... against /tmp/... using path.relative(), which produces a traversal path (../../../private/tmp/...) and incorrectly rejects the file
  • Adds a fs.realpathSync retry fallback — when the initial lexical check fails, both root and resolved paths are canonicalized before re-checking containment
  • Security invariants preserved: traversal attacks still rejected, non-existent paths fall through (realpathSync throws), root-dir-as-path still rejected

Test plan

  • Added 2 new tests for symlink root scenarios (skipped on Windows)
  • All 12 existing + new tests pass (pnpm test -- src/browser/paths.test.ts)
  • TypeScript check passes (pnpm tsgo)
  • Format check passes (oxfmt --check)

🤖 Generated with Claude Code

Greptile Summary

Fixed macOS /tmp symlink issue where upload validation incorrectly rejected valid files. On macOS, /tmp → /private/tmp, causing path.relative() to produce traversal paths when comparing canonicalized file paths against lexical root paths. Added fs.realpathSync fallback that canonicalizes both paths before comparing, preserving all security checks (path traversal still rejected, symlinks still blocked by openFileWithinRoot, non-existent paths handled gracefully).

Confidence Score: 5/5

  • Safe to merge with minimal risk
  • Surgical fix with clear security boundaries preserved - symlink attacks still blocked by openFileWithinRoot, path traversal still rejected, empty catch properly handles non-existent paths, comprehensive test coverage added for both symlink scenarios
  • No files require special attention

Last reviewed commit: 972f0b7

(4/5) You can add custom instructions or style guidelines for the agent here!

On macOS, /tmp is a symlink to /private/tmp. When the CLI resolves
paths via fs.realpath and sends them to the gateway, the gateway's
lexical path.relative() check rejects them because it compares
/private/tmp/... against /tmp/... root, producing a traversal path.

Add a realpath retry fallback in resolvePathWithinRoot() — when the
initial lexical check fails, retry with fs.realpathSync on both root
and resolved paths to handle symlink aliases transparently.

Fixes openclaw#23107

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@PinoHouse
PinoHouse force-pushed the fix/browser-upload-symlink-path branch from 972f0b7 to af479fc Compare February 22, 2026 14:04
@PinoHouse

Copy link
Copy Markdown
Contributor Author

Closing — upstream already resolved this in resolveExistingPathsWithinRoot (added realpath-based fallback in the same function). The fix landed between when the issue was filed and this PR was opened. No additional changes needed.

@PinoHouse PinoHouse closed this Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant