Skip to content

Commit c7ae4ed

Browse files
committed
fix: harden sandbox fs dash-path regression coverage (#25891) (thanks @albertlieyingadrian)
1 parent 5e3502d commit c7ae4ed

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Docs: https://docs.openclaw.ai
4242
- Discord/Voice reliability: restore runtime DAVE dependency (`@snazzah/davey`), add configurable DAVE join options (`channels.discord.voice.daveEncryption` and `channels.discord.voice.decryptionFailureTolerance`), clean up voice listeners/session teardown, guard against stale connection events, and trigger controlled rejoin recovery after repeated decrypt failures to improve inbound STT stability under DAVE receive errors. (#25861, #25372, #24883, #24825, #23890, #23105, #22961, #23421, #23278, #23032)
4343
- Matrix/Read receipts: send read receipts as soon as Matrix messages arrive (before handler pipeline work), so clients no longer show long-lived unread/sent states while replies are processing. (#25841, #25840) Thanks @joshjhall.
4444
- Sandbox/FS bridge: build canonical-path shell scripts with newline separators (not `; ` joins) to avoid POSIX `sh` `do;` syntax errors that broke sandbox file/image read-write operations. (#25737, #25824, #25868) Thanks @DennisGoldfinger and @peteragility.
45+
- Sandbox/FS bridge tests: add regression coverage for dash-leading basenames to confirm sandbox file reads resolve to absolute container paths (and avoid shell-option misdiagnosis for dashed filenames). (#25891) Thanks @albertlieyingadrian.
4546
- Routing/Session isolation: harden followup routing so explicit cross-channel origin replies never fall back to the active dispatcher on route failure, preserve queued overflow summary routing metadata (`channel`/`to`/`thread`) across followup drain, and prefer originating channel context over internal provider tags for embedded followup runs. This prevents webchat/control-ui context from hijacking Discord-targeted replies in shared sessions. (#25864) Thanks @Gamedesigner.
4647
- Messaging tool dedupe: treat originating channel metadata as authoritative for same-target `message.send` suppression in proactive runs (heartbeat/cron/exec-event), including synthetic-provider contexts, so `delivery-mirror` transcript entries no longer cause duplicate Telegram sends. (#25835) Thanks @jadeathena84-arch.
4748
- Cron/Heartbeat delivery: stop inheriting cached session `lastThreadId` for heartbeat-mode target resolution unless a thread/topic is explicitly requested, so announce-mode cron and heartbeat deliveries stay on top-level destinations instead of leaking into active conversation threads. (#25730) Thanks @markshields-tl.

src/agents/sandbox/fs-bridge.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ describe("sandbox fs bridge shell compatibility", () => {
123123
expect(readPath).toContain("file_1095---");
124124
});
125125

126+
it("resolves dash-leading basenames into absolute container paths", async () => {
127+
const bridge = createSandboxFsBridge({ sandbox: createSandbox() });
128+
129+
await bridge.readFile({ filePath: "--leading.txt" });
130+
131+
const readCall = findCallByScriptFragment('cat -- "$1"');
132+
expect(readCall).toBeDefined();
133+
const readPath = readCall ? getDockerPathArg(readCall[0]) : "";
134+
expect(readPath).toBe("/workspace/--leading.txt");
135+
});
136+
126137
it("resolves bind-mounted absolute container paths for reads", async () => {
127138
const sandbox = createSandbox({
128139
docker: {

src/agents/sandbox/fs-bridge.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
9696
const target = this.resolveResolvedPath(params);
9797
await this.assertPathSafety(target, { action: "read files" });
9898
const result = await this.runCommand('set -eu; cat -- "$1"', {
99-
args: [ensurePathNotInterpretedAsOption(target.containerPath)],
99+
args: [target.containerPath],
100100
signal: params.signal,
101101
});
102102
return result.stdout;
@@ -121,7 +121,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
121121
? 'set -eu; cat >"$1"'
122122
: 'set -eu; dir=$(dirname -- "$1"); if [ "$dir" != "." ]; then mkdir -p -- "$dir"; fi; cat >"$1"';
123123
await this.runCommand(script, {
124-
args: [ensurePathNotInterpretedAsOption(target.containerPath)],
124+
args: [target.containerPath],
125125
stdin: buffer,
126126
signal: params.signal,
127127
});
@@ -132,7 +132,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
132132
this.ensureWriteAccess(target, "create directories");
133133
await this.assertPathSafety(target, { action: "create directories", requireWritable: true });
134134
await this.runCommand('set -eu; mkdir -p -- "$1"', {
135-
args: [ensurePathNotInterpretedAsOption(target.containerPath)],
135+
args: [target.containerPath],
136136
signal: params.signal,
137137
});
138138
}
@@ -156,7 +156,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
156156
);
157157
const rmCommand = flags.length > 0 ? `rm ${flags.join(" ")}` : "rm";
158158
await this.runCommand(`set -eu; ${rmCommand} -- "$1"`, {
159-
args: [ensurePathNotInterpretedAsOption(target.containerPath)],
159+
args: [target.containerPath],
160160
signal: params.signal,
161161
});
162162
}
@@ -183,7 +183,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
183183
await this.runCommand(
184184
'set -eu; dir=$(dirname -- "$2"); if [ "$dir" != "." ]; then mkdir -p -- "$dir"; fi; mv -- "$1" "$2"',
185185
{
186-
args: [ensurePathNotInterpretedAsOption(from.containerPath), ensurePathNotInterpretedAsOption(to.containerPath)],
186+
args: [from.containerPath, to.containerPath],
187187
signal: params.signal,
188188
},
189189
);
@@ -197,7 +197,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
197197
const target = this.resolveResolvedPath(params);
198198
await this.assertPathSafety(target, { action: "stat files" });
199199
const result = await this.runCommand('set -eu; stat -c "%F|%s|%Y" -- "$1"', {
200-
args: [ensurePathNotInterpretedAsOption(target.containerPath)],
200+
args: [target.containerPath],
201201
signal: params.signal,
202202
allowFailure: true,
203203
});
@@ -307,7 +307,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
307307
'printf "%s%s\\n" "$canonical" "$suffix"',
308308
].join("\n");
309309
const result = await this.runCommand(script, {
310-
args: [ensurePathNotInterpretedAsOption(params.containerPath), params.allowFinalSymlink ? "1" : "0"],
310+
args: [params.containerPath, params.allowFinalSymlink ? "1" : "0"],
311311
});
312312
const canonical = result.stdout.toString("utf8").trim();
313313
if (!canonical.startsWith("/")) {
@@ -363,19 +363,6 @@ function isPathInsidePosix(root: string, target: string): boolean {
363363
return target === root || target.startsWith(`${root}/`);
364364
}
365365

366-
/**
367-
* Ensure the path is not interpreted as a shell option.
368-
* Paths starting with "-" can be interpreted as command options by the shell.
369-
* Prepend "./" to prevent this interpretation.
370-
*/
371-
function ensurePathNotInterpretedAsOption(path: string): string {
372-
// If path starts with a hyphen (either - or --), prepend ./ to prevent interpretation as option
373-
if (path.startsWith("-") || path.startsWith("--")) {
374-
return "./" + path;
375-
}
376-
return path;
377-
}
378-
379366
async function assertNoHostSymlinkEscape(params: {
380367
absolutePath: string;
381368
rootPath: string;

0 commit comments

Comments
 (0)