Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): r1-m2 validate secret editor return destination
Josué8eab9b7658fb
diff --git a/control-ui/app/secrets/llm/[name]/edit/__tests__/page.test.tsx b/control-ui/app/secrets/llm/[name]/edit/__tests__/page.test.tsxindex 66c66db3c..1e9988a24 100644--- a/control-ui/app/secrets/llm/[name]/edit/__tests__/page.test.tsx+++ b/control-ui/app/secrets/llm/[name]/edit/__tests__/page.test.tsx@@ -204,12 +204,31 @@ describe('Edit LLM secret page — navigation', () => {it('honors an internal from path and returns to it', async () => {seedSecret(['openai-api-key'])- navigation.searchParams = new URLSearchParams({ from: '/agents/foo/model' })+ navigation.searchParams = new URLSearchParams({+ from: '/agents/foo/model?tab=allowed#credentials',+ })+ await renderEditor()++ fireEvent.click(screen.getByRole('button', { name: 'Back to secrets' }))++ expect(navigation.push).toHaveBeenCalledWith('/agents/foo/model?tab=allowed#credentials')+ })++ it.each([+ ['known slash-encoded backslash', 'from=/%5Cattacker.example'],+ ['literal slash-backslash', 'from=/\\attacker.example'],+ ['multiply encoded backslash', 'from=/%255Cattacker.example'],+ ['protocol-relative external URL', 'from=//attacker.example/path'],+ ['normalized protocol-relative path', 'from=/%2e%2e//attacker.example'],+ ['absolute external URL', 'from=https%3A%2F%2Fattacker.example%2Fpath'],+ ])('falls back for %s', async (_caseName, query) => {+ seedSecret(['openai-api-key'])+ navigation.searchParams = new URLSearchParams(query)await renderEditor()fireEvent.click(screen.getByRole('button', { name: 'Back to secrets' }))- expect(navigation.push).toHaveBeenCalledWith('/agents/foo/model')+ expect(navigation.push).toHaveBeenCalledWith('/secrets/llm')})it('ignores a non-internal from value', async () => {diff --git a/control-ui/app/secrets/llm/[name]/edit/page.tsx b/control-ui/app/secrets/llm/[name]/edit/page.tsxindex 9dc95f7a6..42d7b76cf 100644--- a/control-ui/app/secrets/llm/[name]/edit/page.tsx+++ b/control-ui/app/secrets/llm/[name]/edit/page.tsx@@ -49,13 +49,9 @@ function EditLlmSecretContent() {}, [params])// Optional return context for flows that linked here from another surface- // (the agent Models & creds editor). Only same-app paths are honored so the- // param can never aim the back action off-site.+ // (the agent Models & creds editor). Treat it as untrusted until it resolves+ // to a canonical local URL in goBack.const fromParam = (searchParams.get('from') ?? '').trim()- const backTarget =- fromParam.startsWith('/') && !fromParam.startsWith('//')- ? fromParam- : CONTROL_ROUTES.secrets.llmconst [loading, setLoading] = useState(true)const [loadError, setLoadError] = useState('')@@ -100,6 +96,26 @@ function EditLlmSecretContent() {}, [secretName])function goBack() {+ let backTarget: string = CONTROL_ROUTES.secrets.llm+ if (fromParam.startsWith('/') && !fromParam.startsWith('//')) {+ try {+ const origin = window.location.origin+ const destination = new URL(fromParam, origin)+ const hasEncodedBackslash = /%(?:25)*5c/i.test(destination.pathname)+ if (+ destination.origin === origin &&+ destination.pathname.startsWith('/') &&+ !destination.pathname.startsWith('//') &&+ !fromParam.includes('\\') &&+ !destination.pathname.includes('\\') &&+ !hasEncodedBackslash+ ) {+ backTarget = `${destination.pathname}${destination.search}${destination.hash}`+ }+ } catch {+ // Invalid or malformed destinations fall back to the LLM Secrets list.+ }+ }router.push(backTarget)}diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex a9403fe83..5a7ae44ef 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.716",+ "version": "0.1.718","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.716",+ "version": "0.1.718","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 7a1d97d58..7a0c43a3f 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.716",+ "version": "0.1.718","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",