fix(tools): expand tilde in toRelativePathInRoot path validation#30788
Closed
Sid-Qin wants to merge 2 commits intoopenclaw:mainfrom
Closed
fix(tools): expand tilde in toRelativePathInRoot path validation#30788Sid-Qin wants to merge 2 commits intoopenclaw:mainfrom
Sid-Qin wants to merge 2 commits intoopenclaw:mainfrom
Conversation
added 2 commits
March 2, 2026 00:13
Croner can return a past-year timestamp for some timezone/date combinations (e.g. Asia/Shanghai). When nextRun returns a value at or before nowMs, retry from the next whole second and, if still stale, from midnight-tomorrow UTC before giving up. Closes openclaw#30351
The write tool's post-write path verification in toRelativePathInRoot uses path.resolve() which does not expand ~ (tilde). When cron jobs write to paths like ~/agents/.../memory/DATE.md, the verification fails with "Path escapes workspace root" even though the file was successfully written by writeFileWithinRoot (which does expand ~). Apply expandHomePrefix() to both root and candidate before resolving, matching the expansion already done in fs-safe.ts. Closes openclaw#30773
🔒 Aisle Security Analysis✅ We scanned this PR and did not find any security vulnerabilities. Aisle supplements but does not replace security review. Analyzed PR: #30788 at commit |
Contributor
Greptile SummaryThis PR includes two separate bug fixes: 1. Tilde expansion in path validation (primary fix):
2. Croner year-rollback workaround (included but undocumented):
Both fixes are technically sound with no logical errors or security concerns. The tilde expansion follows existing patterns in the codebase ( Confidence Score: 5/5
Last reviewed commit: 16b22f4 |
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
12 tasks
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
13 tasks
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 1, 2026
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
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 3, 2026
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
12 tasks
thomasxm
pushed a commit
to thomasxm/openclaw
that referenced
this pull request
Mar 3, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
agentTurnjobs reports failure (lastRunStatus: "error") even when files are successfully created on disk.consecutiveErrorsincrements indefinitely.toRelativePathInRootinsrc/agents/pi-tools.read.tsnow appliesexpandHomePrefix()to bothrootandcandidatebeforepath.resolve(), matching the expansion already done infs-safe.ts.writeFileWithinRootinfs-safe.ts(already handles tilde), no other tool paths affected.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
~/agents/.../memory/paths will no longer show false errorslastRunStatuswill correctly report"ok"when files are written successfullyconsecutiveErrorswill not increment on successful writesSecurity Impact (required)
NoNoNoNoNoRepro + Verification
Environment
Steps
sessionTarget: "isolated"andpayload.kind: "agentTurn"~/agents/<project>/memory/DATE.mdExpected
lastRunStatus: "ok"Actual
lastRunStatus: "error",consecutiveErrorsincrementslastRunStatus: "ok"Evidence
Root cause:
path.resolve("~/agents/...")treats~as a literal directory name, producing$CWD/~/agents/...instead of/home/user/agents/.... The path verification then fails with "Path escapes workspace root" even thoughwriteFileWithinRoot(which does expand~) succeeded.Fix adds
expandHomePrefix()call beforepath.resolve():Human Verification (required)
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
src/agents/pi-tools.read.tsRisks and Mitigations
None —
expandHomePrefixis already used extensively throughout the codebase for the same purpose.