fix: protect bootstrap files during memory flush#38574
fix: protect bootstrap files during memory flush#38574frankekn merged 7 commits intoopenclaw:mainfrom
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🔵 Sandbox memory flush “append-only” implemented as non-atomic read-then-rewrite (lost updates / overwrite risk)
DescriptionThe sandbox-mode implementation of
This creates a race window and breaks the intended append-only guarantee:
Vulnerable code: const existing = await readOptionalUtf8File({ ... });
const next = `${existing}${separator}${params.content}`;
await params.sandbox.bridge.writeFile({ filePath: params.relativePath, data: next, ... });RecommendationImplement a real append primitive for sandbox mode rather than read+rewrite. Recommended approach:
Example sketch: // in SandboxFsBridge
async appendFile(params: { filePath: string; cwd?: string; data: Buffer | string }) {
const target = this.resolveResolvedPath(params);
this.ensureWriteAccess(target, "append files");
await this.pathGuard.assertPathSafety(target, { action: "append files", requireWritable: true });
const fd = fs.openSync(target.hostPath,
fs.constants.O_WRONLY | fs.constants.O_APPEND | fs.constants.O_NOFOLLOW);
try {
fs.writeSync(fd, Buffer.isBuffer(params.data) ? params.data : Buffer.from(params.data, "utf8"));
} finally {
fs.closeSync(fd);
}
}
If an append primitive cannot be added immediately, a mitigation is to do a compare-and-swap style write (e.g., verify Analyzed PR: #38574 at commit Last updated on: 2026-03-10T05:29:11Z |
Greptile SummaryThis PR hardens the memory-flush feature by injecting three prompt-level guardrails — a target-path hint, an append-only hint, and a read-only hint for workspace bootstrap files — into both the default Key changes:
Minor observation (not a bug): the ordering of hints in Confidence Score: 5/5
Last reviewed commit: 8223806 |
|
Follow-up for the Aisle security finding: this no longer relies on prompt hints alone. This branch now enforces memory-flush writes server-side:
Local verification I ran before pushing this update:
|
26a85a7 to
0be8e1d
Compare
0be8e1d to
a0b9a02
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0b9a02e2e
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (isMemoryFlushRun && !options?.memoryFlushWritePath) { | ||
| throw new Error("memoryFlushWritePath required for memory-triggered tool runs"); |
There was a problem hiding this comment.
Pass memory flush path to memory-triggered tool setup
Require this path only after it is fully plumbed: memory flush runs now call createOpenClawCodingTools with trigger: "memory", but runEmbeddedPiAgent does not forward memoryFlushWritePath into runEmbeddedAttempt (see src/agents/pi-embedded-runner/run.ts call around line 849), so this guard throws and aborts the flush turn whenever memory flush triggers. That means the new protection path can break the entire memory-flush workflow instead of restricting writes.
Useful? React with 👍 / 👎.
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn (cherry picked from commit 96e4975)
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
Merged via squash. Prepared head SHA: a0b9a02 Co-authored-by: frankekn <[email protected]> Co-authored-by: frankekn <[email protected]> Reviewed-by: @frankekn
(cherry picked from commit 96e4975) Co-authored-by: Frank Yang <[email protected]>
(cherry picked from commit 96e4975) Co-authored-by: Frank Yang <[email protected]>
Summary
Describe the problem and fix in 2–5 bullets:
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Pre-compaction memory flushes now explicitly tell the model to write only to
memory/YYYY-MM-DD.md, append instead of overwrite, and treat injected workspace bootstrap files as read-only. Custom memory-flush prompts keep the same safety guardrails.Security Impact (required)
Yes/No): NoYes/No): NoYes/No): NoYes/No): NoYes/No): NoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
DEFAULT_MEMORY_FLUSH_PROMPTandDEFAULT_MEMORY_FLUSH_SYSTEM_PROMPTinsrc/auto-reply/reply/memory-flush.ts.pnpm checkon the clean branch.Expected
pnpm checkshould pass locally.Actual
pnpm checkpasses after syncing dependencies on the neworigin/mainbase.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
memory/YYYY-MM-DD.mdpath; upstream main's canonical-filename warning stays intact after cherry-picking.Compatibility / Migration
Yes/No): YesYes/No): NoYes/No): NoFailure Recovery (if this breaks)
src/auto-reply/reply/memory-flush.tsRisks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.