Skip to content

Commit 394e178

Browse files
authored
fix(sandbox): trim a normalized path's trailing slash without a regex (#10726)
1 parent f0df3cc commit 394e178

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"function": "ghcr.io/simstudioai/sandbox-function:d605a15fb5b0a189",
33
"pi": "ghcr.io/simstudioai/sandbox-pi:42e07cd8cfc98222",
4-
"agent": "ghcr.io/simstudioai/sandbox-agent:7e5faefca4e2c809"
4+
"agent": "ghcr.io/simstudioai/sandbox-agent:036162d0f69789d2"
55
}

‎packages/sandbox-agent-protocol/src/paths.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export function sandboxAgentPathError(path: string): string | null {
2727
export function sandboxAgentFilePathError(path: string): string | null {
2828
if (path.startsWith('/')) return sandboxAgentPathError(path)
2929
if (path.includes('\0')) return 'Path cannot contain a NUL byte'
30-
const normalized = posix.normalize(path).replace(/\/+$/, '')
31-
return normalized === '.' || normalized === '..' || normalized.startsWith('../')
30+
// `normalize` collapses repeated slashes, so at most one trailing slash remains.
31+
const normalized = posix.normalize(path)
32+
const trimmed = normalized.endsWith('/') ? normalized.slice(0, -1) : normalized
33+
return trimmed === '.' || trimmed === '..' || trimmed.startsWith('../')
3234
? 'Path must name something below the home directory'
3335
: null
3436
}

0 commit comments

Comments
 (0)