Repository navigation
fix(exec): replace TOCTOU check-then-read with atomic pinned-fd open in script preflight [AI] - #62333
Conversation
Greptile SummaryThis PR replaces a three-step TOCTOU-vulnerable pattern ( Confidence Score: 5/5Safe to merge — the TOCTOU fix is correct, the isPathInside regex fix is correct, and all remaining findings are informational. Both core changes (TOCTOU fix via atomic readFileWithinRoot, and isPathInside regex tightening) are verified correct by reading the implementation and cross-checking the test coverage. The double sameFileIdentity guard in openVerifiedLocalFile robustly handles post-open swaps even when allowSymlinkTargetWithinRoot=true. All new tests are well-structured and the swap-guard assertions (expect(swapped).toBe(true)) prevent vacuous passes. No P0 or P1 issues found. No files require special attention.
|
|
@greptile review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff285d098b
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ab2eed53b
ℹ️ 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".
|
@greptile review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 894d727656
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18eea98407
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d3eefea8b
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5cfc96c69e
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bb8d36d18
ℹ️ 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".
|
@greptile review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
…in script preflight [AI] (#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
…in script preflight [AI] (openclaw#62333) * fix: address issue * fix: address review feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * address review feedback * fix: address review-pr skill feedback * fix: address PR review feedback * fix: address PR review feedback * fix: address PR review feedback * docs: add changelog entry for PR merge
Summary
assertSandboxPath(),fs.stat(), andfs.readFile()as three separate operations on a mutable pathname, leaving a race window between validation and read. A symlink swap between those steps could redirect the final read to a file outside the sandbox/workspace boundary.readPathWithinRootcall fromsrc/infra/fs-safe.ts, which opens the file withO_NOFOLLOW, performs post-open identity and boundary verification, and reads through the already-verified file descriptor — withmaxBytes: 512 * 1024to preserve the size gate. AllSafeOpenErrorcodes now cause the file to be skipped (best-effort preflight), and non-SafeOpenErrorfailures are re-thrown.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
fs.readFile()re-opened the file by pathname after separateassertSandboxPathandfs.statchecks. Replacing the path between checks and read is possible in environments where the agent has write access to the working directory.readPathWithinRoot/openVerifiedLocalFilesafe-open helpers that now exist insrc/infra/fs-safe.ts.Regression Test Plan (if applicable)
Two new test cases added in
src/agents/bash-tools.exec.script-preflight.test.ts:fs.statto swap the file to an out-of-workdir symlink after the file is already open. Confirms the tool does not surface a preflight error based on the swapped target's content.fs.opento swap the file to an out-of-workdir symlink before the real open is attempted. Verifies thatO_NOFOLLOWcausesELOOP, which is caught asSafeOpenError("symlink") → invalid-path → continue, and no preflight error surfaces.expect(swapped).toBe(true)guards that the swap actually fired.User-visible / Behavior Changes
None. The preflight validator still rejects scripts that contain unescaped shell variable references; the only change is how the file is safely read.
Diagram (if applicable)
Security Impact (required)
readPathWithinRootenforces the samerootDir = workdirconstraint asassertSandboxPathdid, with stronger guarantees.Yes, explain risk + mitigation: N/ARepro + Verification
Environment
security: "full",ask: "off"Steps
pnpm test src/agents/bash-tools.exec.script-preflight.test.tsExpected
Actual
Evidence
fs.stat-spy test would have surfaced a false preflight error with the oldfs.readFilepattern.Human Verification (required)
exec script preflighttests pass.too-large,not-found,outside-workspace,invalid-path, andsymlinkerror codes all result incontinue(skip) rather than throw.Review Conversations
Compatibility / Migration
Risks and Mitigations
readPathWithinRootrejects symlinks unconditionally; if any legitimate workdir scripts are accessed via symlinks inside the workdir, preflight validation would silently skip them (best-effort, so execution still proceeds).assertSandboxPathpath also rejected symlinks viaassertNoPathAliasEscape, so the effective behaviour for symlinked scripts is unchanged.