Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(links): r3-b1 make route normalization idempotent

Josuéb4df2062e199
diff --git a/desktop-app/src/__tests__/sandboxUiDriver.test.ts b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
index 971f07cf1..b9170376c 100644
--- a/desktop-app/src/__tests__/sandboxUiDriver.test.ts
+++ b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
@@ -147,7 +147,9 @@ describe('sandbox UI route normalization', () => {
expect(resolveSandboxUiDefaultPath('/safe/%252e%252e/admin')).toBe('/')
expect(resolveSandboxUiDefaultPath('/safe/%252Fadmin')).toBe('/')
expect(resolveSandboxUiDefaultPath('/tasks\u2028admin')).toBe('/')
- expect(warn).toHaveBeenCalledTimes(3)
+ expect(resolveSandboxUiDefaultPath('/report ')).toBe('/')
+ expect(resolveSandboxUiDefaultPath('/report%20')).toBe('/')
+ expect(warn).toHaveBeenCalledTimes(5)
warn.mockRestore()
})
diff --git a/desktop-app/src/sandboxUiDriver.ts b/desktop-app/src/sandboxUiDriver.ts
index 6fb2f9455..f526cc09d 100644
--- a/desktop-app/src/sandboxUiDriver.ts
+++ b/desktop-app/src/sandboxUiDriver.ts
@@ -530,8 +530,8 @@ export async function applySandboxUiClientRoute(
}
export function resolveSandboxUiDefaultPath(defaultPath?: string): string {
- const rawDefaultPath = String(defaultPath || '').trim()
- if (!rawDefaultPath) return '/'
+ const rawDefaultPath = String(defaultPath || '')
+ if (!rawDefaultPath.trim()) return '/'
const normalized = normalizeSandboxUiDefaultPath(rawDefaultPath)
if (normalized) return normalized
console.warn('[SandboxUI] Invalid recipe defaultPath; falling back to "/":', rawDefaultPath)
@@ -597,8 +597,8 @@ function encodeSandboxUiDefaultPath(defaultPath: string): string {
}
function normalizeSandboxUiDefaultPath(rawPath: string): string | null {
- const routePath = String(rawPath || '').trim()
- if (!routePath) return '/'
+ const routePath = String(rawPath || '')
+ if (!routePath.trim()) return '/'
if (
routePath.length > 4096 ||
routePath.includes('\\') ||
diff --git a/packages/desktop-app-links/index.cjs b/packages/desktop-app-links/index.cjs
index ee5345904..cd9c77c7c 100644
--- a/packages/desktop-app-links/index.cjs
+++ b/packages/desktop-app-links/index.cjs
@@ -31,7 +31,7 @@ function normalizeTeamId(rawTeamId) {
function isUnsafeRouteSegment(rawSegment) {
let segment = rawSegment
for (let depth = 0; depth <= MAX_ROUTE_SEGMENT_DECODE_DEPTH; depth += 1) {
- if (segment === '.' || segment === '..') return true
+ if (segment === '.' || segment === '..' || segment.trim() !== segment) return true
if (
segment.includes('/') ||
segment.includes('\\') ||
@@ -72,7 +72,7 @@ function canonicalizeRouteSegment(rawSegment) {
}
function normalizeSandboxUiRoute(rawPath) {
- const routePath = String(rawPath || '').trim()
+ const routePath = String(rawPath || '')
if (!routePath) return undefined
if (
routePath.length > MAX_APP_ROUTE_LENGTH ||
diff --git a/packages/desktop-app-links/index.test.cjs b/packages/desktop-app-links/index.test.cjs
index aa87b3b25..b6404ca4d 100644
--- a/packages/desktop-app-links/index.test.cjs
+++ b/packages/desktop-app-links/index.test.cjs
@@ -84,6 +84,35 @@ test('route normalization canonicalizes safe percent-encoded paths once', () =>
assert.equal(links.sandboxUiDeepLinkTargetsEqual(unicode, decoded), true)
})
+test('route normalization rejects unstable segment-edge whitespace', () => {
+ for (const input of ['/report ', '/report%20', '/%20report', '/.%20']) {
+ assert.equal(links.normalizeSandboxUiRoute(input), null)
+ }
+
+ const canonical = links.normalizeSandboxUiRoute('/report summary')
+ assert.equal(canonical, '/report summary')
+ assert.equal(links.normalizeSandboxUiRoute(canonical), canonical)
+
+ const parsed = links.parseSandboxUiDeepLink(
+ links.buildSandboxUiDeepLink({
+ recipeNs: 'sandbox-recipes',
+ recipeName: 'reporting',
+ path: canonical,
+ })
+ )
+ assert.deepEqual(parsed, {
+ appRef: 'sandbox-recipes/reporting',
+ path: canonical,
+ })
+ assert.equal(
+ links.sandboxUiDeepLinkTargetsEqual(
+ { appRef: 'sandbox-recipes/reporting', path: canonical },
+ parsed
+ ),
+ true
+ )
+})
+
test('shared app links carry only client-side pathnames', () => {
for (const pathValue of [
'/tasks?authorization=secret',