fix(edit): return accurate error for paths outside workspace root#30752
fix(edit): return accurate error for paths outside workspace root#30752Jimmy-xuzimo wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryFixed misleading error message when Edit tool receives paths outside workspace root. Previously returned "File not found" when
Confidence Score: 5/5
Last reviewed commit: 12efc98 |
The Edit tool returned a misleading 'File not found' error when given an absolute path outside the agent's workspace root. This was because toRelativePathInRoot throws 'Path escapes workspace root' but the error was not being converted to an EACCES error code. This fix ensures that when a path is outside the workspace, the access function throws an EACCES error with a clear 'Path escapes workspace root' message, allowing pi-coding-agent's createEditTool to distinguish it from ENOENT (file not found) and show the correct error message. - Fixes openclaw#30724 - Related to openclaw#30711 - Adds tests for workspace escape error handling
4930c76 to
5d7ab61
Compare
|
@openclaw/maintainers @byungsker ✅ Update: This PR has been updated:
This fix addresses issue #30724 where the Edit tool returned misleading "File not found" errors for paths outside workspace root. Now it correctly returns "Path escapes workspace root" with EACCES error code. Ready for review and merge! 🚀 Contributed by @Jimmy-xuzimo |
|
Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd |
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
|
Superseded by a landed fix on .
Closing this PR as duplicate/superseded to keep one canonical patch path. |
|
Correction with exact refs:
|
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
path.resolve() treats ~ as a literal directory name, so ~/file.txt resolved to <cwd>/~/file.txt instead of /home/user/file.txt. Add expandHomePrefix() before path.resolve() in all affected tool path resolution points: - Host write operations (mkdir, writeFile) in non-workspace mode - Host edit operations (readFile, writeFile, access) in non-workspace mode - toRelativePathInRoot() workspace boundary validator (affects all tools) - resolveWorkdir() for non-sandbox exec/bash working directory - parseSandboxBindMount() for Docker bind mount host paths The host read tool and sandbox tools already handled tilde via the upstream library's expandPath(). Closes openclaw#30669 Related: openclaw#30782, openclaw#30788, openclaw#30744, openclaw#30770, openclaw#30756, openclaw#30753, openclaw#30752, openclaw#30747
Summary
File not founderror when given an absolute path outside the agent's workspace root. This was becausetoRelativePathInRootthrows"Path escapes workspace root"but the error was not being converted to an EACCES error code.accessfunction increateHostEditOperationsto catch thetoRelativePathInRooterror and convert it to an EACCES error with a clear message, allowingpi-coding-agent'screateEditToolto distinguish it from ENOENT (file not found).Change Type
Scope
Linked Issue/PR
User-visible / Behavior Changes
Path escapes workspace root: <path>instead ofFile not foundwhen attempting to edit files outside the workspace.Security Impact
NoNoNoNoNoRepro + Verification
Environment
Steps
{ "tool": "edit", "path": "/path/outside/workspace/file.txt", "oldText": "a", "newText": "b" }Expected
Actual
File not found: /path/outside/workspace/file.txtPath escapes workspace root: /path/outside/workspace/file.txtEvidence
Commands run:
pnpm exec vitest run src/agents/pi-tools.read.workspace-escape-error.test.tspnpm exec vitest run src/agents/pi-tools.read.host-edit-access.test.tspnpm exec oxlint --type-aware src/agents/pi-tools.read.tspnpm exec oxfmt --check src/agents/pi-tools.read.tsHuman Verification
../outside/file.txt).Compatibility / Migration
YesNoNoFailure Recovery
src/agents/pi-tools.read.tsRisks and Mitigations
Contributed by @Jimmy-xuzimo