diff --git a/ui/desktop/src/App.test.tsx b/ui/desktop/src/App.test.tsx index db55e4661..9cbb09ba0 100644 --- a/ui/desktop/src/App.test.tsx +++ b/ui/desktop/src/App.test.tsx @@ -169,7 +169,7 @@ const mockElectron = { on: vi.fn(), off: vi.fn(), reactReady: vi.fn(), - getAllowedExtensions: vi.fn().mockResolvedValue([]), + getAllowedExtensions: vi.fn().mockResolvedValue(null), platform: 'darwin', createChatWindow: vi.fn(), getSetting: vi.fn().mockResolvedValue(null), diff --git a/ui/desktop/src/allowlistFetcher.test.ts b/ui/desktop/src/allowlistFetcher.test.ts new file mode 100644 index 000000000..ff967d19a --- /dev/null +++ b/ui/desktop/src/allowlistFetcher.test.ts @@ -0,0 +1,231 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { EventEmitter } from 'events'; +import type { IncomingMessage, ClientRequest, RequestOptions } from 'node:http'; + +type GetFn = ( + url: string | URL, + options: RequestOptions, + cb: (res: IncomingMessage) => void +) => ClientRequest; + +const { mockHttpsGet } = vi.hoisted(() => ({ mockHttpsGet: vi.fn() })); + +vi.mock('node:https', () => ({ + default: { get: mockHttpsGet }, +})); + +import { fetchAllowlistContent, parseAllowlistCommands } from './allowlistFetcher'; + +type MockResponse = EventEmitter & { + statusCode: number; + headers: Record; + setEncoding: ReturnType; + resume: ReturnType; +}; + +function mockResponse(statusCode: number, headers: Record = {}): MockResponse { + const res = new EventEmitter() as MockResponse; + res.statusCode = statusCode; + res.headers = headers; + res.setEncoding = vi.fn(); + res.resume = vi.fn(); + return res; +} + +function mockRequest(): EventEmitter { + return new EventEmitter(); +} + +describe('fetchAllowlistContent', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('rejects an HTTP initial URL without making a network request', async () => { + await expect(fetchAllowlistContent('http://example.com/policy.yaml')).rejects.toThrow( + 'GOOSE_ALLOWLIST must use HTTPS' + ); + expect(mockHttpsGet).not.toHaveBeenCalled(); + }); + + it('rejects a redirect to HTTP before contacting the redirect target', async () => { + const req = mockRequest(); + mockHttpsGet.mockImplementation((_url, _options, cb) => { + const res = mockResponse(301, { location: 'http://evil.com/policy.yaml' }); + cb(res as unknown as IncomingMessage); + return req as unknown as ClientRequest; + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'GOOSE_ALLOWLIST must use HTTPS' + ); + expect(mockHttpsGet).toHaveBeenCalledTimes(1); + expect(mockHttpsGet).toHaveBeenCalledWith( + 'https://example.com/policy.yaml', + expect.objectContaining({ signal: expect.any(AbortSignal) }), + expect.any(Function) + ); + }); + + it('returns body content for a valid HTTPS 200 response', async () => { + const req = mockRequest(); + mockHttpsGet.mockImplementation((_url, options, cb) => { + expect(options.headers).toEqual({ 'accept-encoding': 'identity' }); + const res = mockResponse(200); + cb(res as unknown as IncomingMessage); + setTimeout(() => { + res.emit('data', 'extensions:\n'); + res.emit('data', ' - id: x\n command: npx x\n'); + res.emit('end'); + }, 0); + return req as unknown as ClientRequest; + }); + + const content = await fetchAllowlistContent('https://example.com/policy.yaml'); + expect(content).toContain('extensions:'); + expect(content).toContain('npx x'); + }); + + it('propagates certificate and network errors', async () => { + const req = mockRequest(); + mockHttpsGet.mockImplementation((_url, _options, _cb) => { + setTimeout(() => req.emit('error', new Error('certificate has expired')), 0); + return req as unknown as ClientRequest; + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'certificate has expired' + ); + }); + + it('aborts the active request after a terminal response', async () => { + const req = mockRequest(); + const res = mockResponse(404); + let signal: AbortSignal | undefined; + mockHttpsGet.mockImplementation((_url, options, cb) => { + signal = options.signal as AbortSignal; + setTimeout(() => cb(res as unknown as IncomingMessage), 0); + return req as unknown as ClientRequest; + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'Allowlist fetch failed: HTTP 404' + ); + expect(signal?.aborted).toBe(true); + }); + + it('follows HTTPS-to-HTTPS redirects and aborts remaining streams', async () => { + let callCount = 0; + let signal: AbortSignal | undefined; + mockHttpsGet.mockImplementation((_url, options, cb) => { + signal = options.signal as AbortSignal; + const req = mockRequest(); + callCount++; + if (callCount === 1) { + const res = mockResponse(301, { location: 'https://cdn.example.com/policy.yaml' }); + cb(res as unknown as IncomingMessage); + } else { + const res = mockResponse(200); + cb(res as unknown as IncomingMessage); + setTimeout(() => { + res.emit('data', 'extensions: []'); + res.emit('end'); + }, 0); + } + return req as unknown as ClientRequest; + }); + + const content = await fetchAllowlistContent('https://example.com/policy.yaml'); + expect(content).toBe('extensions: []'); + expect(signal?.aborted).toBe(true); + expect(mockHttpsGet).toHaveBeenCalledTimes(2); + expect(mockHttpsGet).toHaveBeenNthCalledWith( + 2, + 'https://cdn.example.com/policy.yaml', + expect.objectContaining({ signal: expect.any(AbortSignal) }), + expect.any(Function) + ); + }); + + it('rejects a malformed redirect URL', async () => { + const req = mockRequest(); + const res = mockResponse(301, { location: 'http://[' }); + mockHttpsGet.mockImplementation((_url, _options, cb) => { + setTimeout(() => cb(res as unknown as IncomingMessage), 0); + return req as unknown as ClientRequest; + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'Invalid allowlist redirect URL' + ); + expect(mockHttpsGet).toHaveBeenCalledTimes(1); + expect(res.resume).toHaveBeenCalledOnce(); + }); + + it('rejects after too many redirects', async () => { + mockHttpsGet.mockImplementation((_url, _options, cb) => { + const req = mockRequest(); + const res = mockResponse(301, { location: 'https://example.com/loop' }); + cb(res as unknown as IncomingMessage); + return req as unknown as ClientRequest; + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'Too many redirects' + ); + }); + + it('aborts when the total fetch duration expires', async () => { + vi.useFakeTimers(); + try { + const req = mockRequest(); + let signal: AbortSignal | undefined; + mockHttpsGet.mockImplementation((_url, options, _cb) => { + signal = options.signal as AbortSignal; + return req as unknown as ClientRequest; + }); + + const rejection = expect( + fetchAllowlistContent('https://example.com/policy.yaml') + ).rejects.toThrow('Allowlist fetch timed out'); + await vi.advanceTimersByTimeAsync(30_000); + + await rejection; + expect(signal?.aborted).toBe(true); + } finally { + vi.useRealTimers(); + } + }); + + it('rejects when https.get throws synchronously', async () => { + mockHttpsGet.mockImplementation(() => { + throw new Error('Invalid URI'); + }); + + await expect(fetchAllowlistContent('https://example.com/policy.yaml')).rejects.toThrow( + 'Invalid URI' + ); + }); +}); + +describe('parseAllowlistCommands', () => { + it('returns commands from a valid policy', () => { + expect( + parseAllowlistCommands('extensions:\n - id: example\n command: npx example\n') + ).toEqual(['npx example']); + }); + + it('preserves a configured empty policy as deny-all', () => { + expect(parseAllowlistCommands('extensions: []')).toEqual([]); + }); + + it.each([ + ['', 'expected an extensions array'], + ['name: login-page', 'expected an extensions array'], + ['extensions: invalid', 'expected an extensions array'], + ['extensions:\n - id: missing-command', 'requires a command'], + ['extensions:\n - command: ""', 'requires a command'], + ])('rejects an invalid policy', (content, message) => { + expect(() => parseAllowlistCommands(content)).toThrow(message); + }); +}); diff --git a/ui/desktop/src/allowlistFetcher.ts b/ui/desktop/src/allowlistFetcher.ts new file mode 100644 index 000000000..2e4f1b54a --- /dev/null +++ b/ui/desktop/src/allowlistFetcher.ts @@ -0,0 +1,120 @@ +import https from 'node:https'; +import * as yaml from 'yaml'; + +const ALLOWLIST_FETCH_TIMEOUT_MS = 30_000; + +export function parseAllowlistCommands(content: string): string[] { + const parsed: unknown = yaml.parse(content); + + if ( + !parsed || + typeof parsed !== 'object' || + !Array.isArray((parsed as { extensions?: unknown }).extensions) + ) { + throw new Error('Invalid GOOSE_ALLOWLIST policy: expected an extensions array'); + } + + return (parsed as { extensions: unknown[] }).extensions.map((extension, index) => { + if ( + !extension || + typeof extension !== 'object' || + typeof (extension as { command?: unknown }).command !== 'string' || + (extension as { command: string }).command.trim() === '' + ) { + throw new Error(`Invalid GOOSE_ALLOWLIST policy: extension ${index} requires a command`); + } + + return (extension as { command: string }).command; + }); +} + +export function fetchAllowlistContent(url: string): Promise { + return new Promise((resolve, reject) => { + const controller = new AbortController(); + let settled = false; + + const finishResolve = (content: string) => { + if (settled) return; + settled = true; + clearTimeout(timeout); + resolve(content); + controller.abort(); + }; + + const finishReject = (error: Error) => { + if (settled) return; + settled = true; + clearTimeout(timeout); + reject(error); + controller.abort(); + }; + + const timeout = setTimeout(() => { + finishReject(new Error('Allowlist fetch timed out')); + }, ALLOWLIST_FETCH_TIMEOUT_MS); + + const follow = (currentUrl: string, depth: number) => { + if (settled) return; + if (depth > 10) { + finishReject(new Error('Too many redirects fetching allowlist')); + return; + } + let parsed: URL; + try { + parsed = new URL(currentUrl); + } catch { + finishReject(new Error(`Invalid allowlist URL: ${currentUrl}`)); + return; + } + if (parsed.protocol !== 'https:') { + finishReject(new Error(`GOOSE_ALLOWLIST must use HTTPS: ${currentUrl}`)); + return; + } + try { + https + .get( + currentUrl, + { signal: controller.signal, headers: { 'accept-encoding': 'identity' } }, + (res) => { + if (settled) { + res.resume(); + return; + } + const { statusCode } = res; + if (statusCode && statusCode >= 300 && statusCode < 400) { + const location = res.headers.location; + if (!location) { + finishReject(new Error('Allowlist redirect missing Location header')); + return; + } + res.resume(); + let redirectUrl: string; + try { + redirectUrl = new URL(location, currentUrl).href; + } catch { + finishReject(new Error(`Invalid allowlist redirect URL: ${location}`)); + return; + } + follow(redirectUrl, depth + 1); + } else if (statusCode && statusCode >= 200 && statusCode < 300) { + let data = ''; + res.setEncoding('utf8'); + res.on('data', (chunk: string) => { + if (!settled) data += chunk; + }); + res.on('end', () => finishResolve(data)); + res.on('error', finishReject); + } else { + res.resume(); + finishReject(new Error(`Allowlist fetch failed: HTTP ${statusCode}`)); + } + } + ) + .on('error', finishReject); + } catch (error) { + finishReject(error instanceof Error ? error : new Error(String(error))); + } + }; + follow(url, 0); + }); +} diff --git a/ui/desktop/src/components/ExtensionInstallModal.test.tsx b/ui/desktop/src/components/ExtensionInstallModal.test.tsx index 7524bf31a..2702b24f1 100644 --- a/ui/desktop/src/components/ExtensionInstallModal.test.tsx +++ b/ui/desktop/src/components/ExtensionInstallModal.test.tsx @@ -53,9 +53,11 @@ describe('ExtensionInstallModal', () => { describe('Extension Request Handling', () => { it('should handle trusted extension (default behaviour, no allowlist)', async () => { - mockElectron.getAllowedExtensions.mockResolvedValue([]); + mockElectron.getAllowedExtensions.mockResolvedValue(null); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); @@ -72,7 +74,9 @@ describe('ExtensionInstallModal', () => { it('should handle trusted extension (from allowlist)', async () => { mockElectron.getAllowedExtensions.mockResolvedValue(['npx test-extension']); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); @@ -90,7 +94,9 @@ describe('ExtensionInstallModal', () => { }); mockElectron.getAllowedExtensions.mockResolvedValue(['uvx allowed-package']); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); @@ -109,7 +115,9 @@ describe('ExtensionInstallModal', () => { it('should handle blocked extension', async () => { mockElectron.getAllowedExtensions.mockResolvedValue(['uvx allowed-package']); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); @@ -122,13 +130,53 @@ describe('ExtensionInstallModal', () => { expect(screen.getAllByRole('button')).toHaveLength(2); expect(screen.getByText(/Contact your administrator/)).toBeInTheDocument(); }); + + it('should block every extension when the configured allowlist is empty', async () => { + mockElectron.getAllowedExtensions.mockResolvedValue([]); + + renderWithIntl( + + ); + + const eventHandler = getAddExtensionEventHandler(); + + await act(async () => { + await eventHandler({}, 'goose://extension?cmd=npx&arg=blocked-extension&name=BlockedExt'); + }); + + expect(screen.getByText('Extension Installation Blocked')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'OK' })).toBeInTheDocument(); + }); + + it('should block installation and show policy error when allowlist fetch fails', async () => { + mockElectron.getAllowedExtensions.mockRejectedValue( + new Error('GOOSE_ALLOWLIST must use HTTPS: http://example.com/policy.yaml') + ); + + renderWithIntl( + + ); + + const eventHandler = getAddExtensionEventHandler(); + + await act(async () => { + await eventHandler({}, 'goose://extension?cmd=npx&arg=some-extension&name=SomeExt'); + }); + + expect(screen.getByText('Extension Policy Unavailable')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'OK' })).toBeInTheDocument(); + expect(screen.getAllByRole('button')).toHaveLength(2); + expect(screen.getByText(/allowlist policy could not be retrieved/)).toBeInTheDocument(); + }); }); describe('Modal Actions', () => { it('should dismiss modal correctly', async () => { - mockElectron.getAllowedExtensions.mockResolvedValue([]); + mockElectron.getAllowedExtensions.mockResolvedValue(null); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); @@ -147,9 +195,11 @@ describe('ExtensionInstallModal', () => { it('should handle successful extension installation', async () => { vi.mocked(addExtensionFromDeepLink).mockResolvedValue(undefined); - mockElectron.getAllowedExtensions.mockResolvedValue([]); + mockElectron.getAllowedExtensions.mockResolvedValue(null); - renderWithIntl(); + renderWithIntl( + + ); const eventHandler = getAddExtensionEventHandler(); diff --git a/ui/desktop/src/components/ExtensionInstallModal.tsx b/ui/desktop/src/components/ExtensionInstallModal.tsx index 6ac6f3bf3..adc95ca74 100644 --- a/ui/desktop/src/components/ExtensionInstallModal.tsx +++ b/ui/desktop/src/components/ExtensionInstallModal.tsx @@ -36,6 +36,15 @@ const i18n = defineMessages({ id: 'extensionInstallModal.ok', defaultMessage: 'OK', }, + policyErrorTitle: { + id: 'extensionInstallModal.policyErrorTitle', + defaultMessage: 'Extension Policy Unavailable', + }, + policyErrorMessage: { + id: 'extensionInstallModal.policyErrorMessage', + defaultMessage: + 'The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available.\n\nContact your administrator to check the GOOSE_ALLOWLIST configuration.', + }, untrustedTitle: { id: 'extensionInstallModal.untrustedTitle', defaultMessage: 'Install Untrusted Extension?', @@ -94,7 +103,7 @@ const i18n = defineMessages({ }, }); -type ModalType = 'blocked' | 'untrusted' | 'trusted'; +type ModalType = 'blocked' | 'untrusted' | 'trusted' | 'policy-error'; interface ExtensionInfo { name: string; @@ -179,7 +188,7 @@ export function ExtensionInstallModal({ addExtension, setView }: ExtensionInstal const allowedCommands = await window.electron.getAllowedExtensions(); - if (!allowedCommands || allowedCommands.length === 0) { + if (allowedCommands === null) { return 'trusted'; } @@ -190,7 +199,7 @@ export function ExtensionInstallModal({ addExtension, setView }: ExtensionInstal return isCommandAllowed ? 'trusted' : 'blocked'; } catch (error) { console.error('Error checking allowlist:', error); - return 'trusted'; + return 'policy-error'; } }; @@ -237,6 +246,16 @@ export function ExtensionInstallModal({ addExtension, setView }: ExtensionInstal }; } + case 'policy-error': + return { + title: intl.formatMessage(i18n.policyErrorTitle), + message: '\n\n' + intl.formatMessage(i18n.policyErrorMessage), + confirmLabel: intl.formatMessage(i18n.ok), + cancelLabel: '', + showSingleButton: true, + isBlocked: true, + }; + case 'trusted': default: return { diff --git a/ui/desktop/src/i18n/messages/de.json b/ui/desktop/src/i18n/messages/de.json index 66ffe6438..d97e8cb55 100644 --- a/ui/desktop/src/i18n/messages/de.json +++ b/ui/desktop/src/i18n/messages/de.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Möchten Sie die Erweiterung {name} wirklich installieren? Befehl: {command}" }, diff --git a/ui/desktop/src/i18n/messages/en.json b/ui/desktop/src/i18n/messages/en.json index b22063679..f445f1c09 100644 --- a/ui/desktop/src/i18n/messages/en.json +++ b/ui/desktop/src/i18n/messages/en.json @@ -1100,6 +1100,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Are you sure you want to install the {name} extension? Command: {command}" }, diff --git a/ui/desktop/src/i18n/messages/es.json b/ui/desktop/src/i18n/messages/es.json index fab198d64..162919074 100644 --- a/ui/desktop/src/i18n/messages/es.json +++ b/ui/desktop/src/i18n/messages/es.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "¿Seguro que quieres instalar la extensión {name}? Comando: {command}" }, diff --git a/ui/desktop/src/i18n/messages/fr.json b/ui/desktop/src/i18n/messages/fr.json index bbe33cac1..6350a2933 100644 --- a/ui/desktop/src/i18n/messages/fr.json +++ b/ui/desktop/src/i18n/messages/fr.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Voulez-vous vraiment installer l'extension {name} ? Commande : {command}" }, diff --git a/ui/desktop/src/i18n/messages/hi.json b/ui/desktop/src/i18n/messages/hi.json index a370aa134..85bbe17c4 100644 --- a/ui/desktop/src/i18n/messages/hi.json +++ b/ui/desktop/src/i18n/messages/hi.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "ठीक है" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "क्या आप वाकई {name} एक्सटेंशन इंस्टॉल करना चाहते हैं? आदेश: {command}" }, diff --git a/ui/desktop/src/i18n/messages/id.json b/ui/desktop/src/i18n/messages/id.json index dcb833a3c..3b04d4462 100644 --- a/ui/desktop/src/i18n/messages/id.json +++ b/ui/desktop/src/i18n/messages/id.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Apakah Anda yakin ingin memasang ekstensi {name}? Perintah: {command}" }, diff --git a/ui/desktop/src/i18n/messages/it.json b/ui/desktop/src/i18n/messages/it.json index 314745782..c4dd3a131 100644 --- a/ui/desktop/src/i18n/messages/it.json +++ b/ui/desktop/src/i18n/messages/it.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Vuoi davvero installare l'estensione {name}? Comando: {command}" }, diff --git a/ui/desktop/src/i18n/messages/ja.json b/ui/desktop/src/i18n/messages/ja.json index ce179dc24..fdeb378bf 100644 --- a/ui/desktop/src/i18n/messages/ja.json +++ b/ui/desktop/src/i18n/messages/ja.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "{name}拡張機能をインストールしてもよろしいですか?コマンド: {command}" }, diff --git a/ui/desktop/src/i18n/messages/ko.json b/ui/desktop/src/i18n/messages/ko.json index 8353c08cb..f67df1039 100644 --- a/ui/desktop/src/i18n/messages/ko.json +++ b/ui/desktop/src/i18n/messages/ko.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "확인" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "{name} 익스텐션을 설치하시겠습니까? 명령: {command}" }, diff --git a/ui/desktop/src/i18n/messages/ms.json b/ui/desktop/src/i18n/messages/ms.json index fb35f2a75..99c1c312a 100644 --- a/ui/desktop/src/i18n/messages/ms.json +++ b/ui/desktop/src/i18n/messages/ms.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Adakah anda pasti mahu memasang sambungan {name}? Arahan: {command}" }, diff --git a/ui/desktop/src/i18n/messages/pt.json b/ui/desktop/src/i18n/messages/pt.json index bb0fbd3f0..d3cbaa349 100644 --- a/ui/desktop/src/i18n/messages/pt.json +++ b/ui/desktop/src/i18n/messages/pt.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Tem certeza de que deseja instalar a extensão {name}? Comando: {command}" }, diff --git a/ui/desktop/src/i18n/messages/ru.json b/ui/desktop/src/i18n/messages/ru.json index 8f7337f4e..9a59ccb55 100644 --- a/ui/desktop/src/i18n/messages/ru.json +++ b/ui/desktop/src/i18n/messages/ru.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Установить расширение {name}? Команда: {command}" }, diff --git a/ui/desktop/src/i18n/messages/tr.json b/ui/desktop/src/i18n/messages/tr.json index e02b94ab4..669908615 100644 --- a/ui/desktop/src/i18n/messages/tr.json +++ b/ui/desktop/src/i18n/messages/tr.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "tamam" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "{name} uzantısını yüklemek istediğinizden emin misiniz? Komut: {command}" }, diff --git a/ui/desktop/src/i18n/messages/vi.json b/ui/desktop/src/i18n/messages/vi.json index c2811c3b7..f78a49d8c 100644 --- a/ui/desktop/src/i18n/messages/vi.json +++ b/ui/desktop/src/i18n/messages/vi.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "OK" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "Bạn có chắc chắn muốn cài đặt tiện ích mở rộng {name} không? Lệnh: {command}" }, diff --git a/ui/desktop/src/i18n/messages/zh-CN.json b/ui/desktop/src/i18n/messages/zh-CN.json index 4976882c0..f61f86f35 100644 --- a/ui/desktop/src/i18n/messages/zh-CN.json +++ b/ui/desktop/src/i18n/messages/zh-CN.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "确定" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "确定要安装 {name} 扩展吗?命令:{command}" }, diff --git a/ui/desktop/src/i18n/messages/zh-TW.json b/ui/desktop/src/i18n/messages/zh-TW.json index 874a77874..4ccbcd7db 100644 --- a/ui/desktop/src/i18n/messages/zh-TW.json +++ b/ui/desktop/src/i18n/messages/zh-TW.json @@ -1091,6 +1091,12 @@ "extensionInstallModal.ok": { "defaultMessage": "確定" }, + "extensionInstallModal.policyErrorMessage": { + "defaultMessage": "The extension allowlist policy could not be retrieved. Extension installation is blocked until the policy is available. Contact your administrator to check the GOOSE_ALLOWLIST configuration." + }, + "extensionInstallModal.policyErrorTitle": { + "defaultMessage": "Extension Policy Unavailable" + }, "extensionInstallModal.trustedMessage": { "defaultMessage": "您確定要安裝 {name} 擴充功能嗎?命令:{command}" }, diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index a9d020d4f..38e4a7dac 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -18,6 +18,7 @@ import { Tray, } from 'electron'; import { pathToFileURL, format as formatUrl, URLSearchParams } from 'node:url'; +import { fetchAllowlistContent, parseAllowlistCommands } from './allowlistFetcher'; import { Buffer } from 'node:buffer'; import fs from 'node:fs/promises'; import fsSync from 'node:fs'; @@ -42,7 +43,6 @@ import { isRetiredGooseChatApp } from './utils/retiredApps'; import type { Settings, SettingKey } from './utils/settings'; import { defaultSettings, getKeyboardShortcuts } from './utils/settings'; import * as crypto from 'crypto'; -import * as yaml from 'yaml'; import windowStateKeeper from 'electron-window-state'; import { getUpdateAvailable, @@ -3078,34 +3078,13 @@ app.whenReady().then(async () => { } }); -async function getAllowList(): Promise { +async function getAllowList(): Promise { if (!process.env.GOOSE_ALLOWLIST) { - return []; + return null; } - const response = await fetch(process.env.GOOSE_ALLOWLIST); - - if (!response.ok) { - throw new Error( - `Failed to fetch allowed extensions: ${response.status} ${response.statusText}` - ); - } - - // Parse the YAML content - const yamlContent = await response.text(); - const parsedYaml = yaml.parse(yamlContent); - - // Extract the commands from the extensions array - if (parsedYaml && parsedYaml.extensions && Array.isArray(parsedYaml.extensions)) { - const commands = parsedYaml.extensions.map( - (ext: { id: string; command: string }) => ext.command - ); - console.log(`Fetched ${commands.length} allowed extension commands`); - return commands; - } else { - console.error('Invalid YAML structure:', parsedYaml); - return []; - } + const yamlContent = await fetchAllowlistContent(process.env.GOOSE_ALLOWLIST); + return parseAllowlistCommands(yamlContent); } app.on('will-quit', async () => { diff --git a/ui/desktop/src/preload.ts b/ui/desktop/src/preload.ts index 4044cd4bf..01daa468b 100644 --- a/ui/desktop/src/preload.ts +++ b/ui/desktop/src/preload.ts @@ -124,7 +124,7 @@ type ElectronAPI = { writeFile: (directory: string, content: string) => Promise; ensureDirectory: (dirPath: string) => Promise; listFiles: (dirPath: string, extension?: string) => Promise; - getAllowedExtensions: () => Promise; + getAllowedExtensions: () => Promise; getPathForFile: (file: File) => string; setMenuBarIcon: (show: boolean) => Promise; getMenuBarIconState: () => Promise;