Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions documentation/docs/guides/remote-goose-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ If you intend to reach the server from another machine, also test from there usi

When `goose serve` runs with TLS, it generates or loads a TLS certificate. goose Desktop can pin that certificate by SHA-256 fingerprint. If you leave the fingerprint field empty, goose Desktop uses trust-on-first-use and pins the first certificate it sees for that backend.

A configured fingerprint applies to the backend's HTTPS origin, including its port. Redirects within that origin can change the path. Without a configured fingerprint, the `/status` check can follow redirects without credentials. The secret goes only to the final `/status` origin. HTTPS-to-HTTP redirects are rejected in both cases.

Changes to the configured fingerprint apply to new connections. Close and reopen a window to reconnect with an updated fingerprint.

When TLS is enabled, `goose serve` logs the fingerprint on startup. It looks like:

```text
Expand Down
61 changes: 6 additions & 55 deletions ui/desktop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,13 @@
/>
<title>Goose</title>
<script>
// Initialize theme before any content loads
(function () {
function initializeTheme() {
try {
if (window.localStorage) {
const useSystemTheme = localStorage.getItem('use_system_theme') === 'true';
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const savedTheme = localStorage.getItem('theme');
const isDark = useSystemTheme
? systemPrefersDark
: savedTheme
? savedTheme === 'dark'
: systemPrefersDark;

if (isDark) {
document.documentElement.classList.add('dark');
document.documentElement.style.colorScheme = 'dark';
} else {
document.documentElement.classList.remove('dark');
document.documentElement.style.colorScheme = 'light';
}
} else {
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (systemPrefersDark) {
document.documentElement.classList.add('dark');
document.documentElement.style.colorScheme = 'dark';
} else {
document.documentElement.classList.remove('dark');
document.documentElement.style.colorScheme = 'light';
}
}
} catch (error) {
console.warn(
'Failed to initialize theme from localStorage, using system preference:',
error
);
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (systemPrefersDark) {
document.documentElement.classList.add('dark');
document.documentElement.style.colorScheme = 'dark';
} else {
document.documentElement.classList.remove('dark');
document.documentElement.style.colorScheme = 'light';
}
}
}

// Run immediately
initializeTheme();

// Retry after DOM is ready if initial attempt failed
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function () {
setTimeout(initializeTheme, 50);
});
}
const useSystemTheme = window.appConfig?.get('GOOSE_USE_SYSTEM_THEME') !== false;
const isDark = useSystemTheme
? window.matchMedia('(prefers-color-scheme: dark)').matches
: window.appConfig?.get('GOOSE_THEME') === 'dark';
document.documentElement.classList.toggle('dark', isDark);
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light';
})();
</script>
<link href="./src/styles/main.css" rel="stylesheet" />
Expand Down
63 changes: 53 additions & 10 deletions ui/desktop/src/backendCertificateVerifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'node:fs';
import path from 'node:path';
import type { Session } from 'electron';
import { describe, expect, it, vi } from 'vitest';
import {
installBackendCertificateVerifiers,
installScopedCertificateVerifier,
type BackendCertificateTrustVerifier,
type ScopedCertificateTrust,
} from './backendCertificateVerifier';

type CertificateVerifyProc = Exclude<Parameters<Session['setCertificateVerifyProc']>[0], null>;
Expand Down Expand Up @@ -76,14 +76,6 @@ function createFixture(initialPins: Record<string, string | null>) {
}

describe('backend certificate verifier wiring', () => {
it('covers the renderer session that opens ACP WebSockets', () => {
const source = fs.readFileSync(path.resolve('src/main.ts'), 'utf8');

expect(source).toMatch(
/installBackendCertificateVerifiers\([\s\S]{0,200}session\.defaultSession[\s\S]{0,200}session\.fromPartition\('persist:goose'\)/
);
});

it.each(['defaultSession', 'rendererSession'] as const)(
'enforces explicit pin matches and mismatches on %s',
(sessionName) => {
Expand Down Expand Up @@ -115,3 +107,54 @@ describe('backend certificate verifier wiring', () => {
expect(fixture.trust.verify).not.toHaveBeenCalled();
});
});

describe('installScopedCertificateVerifier', () => {
function createScopedFixture(trust: ScopedCertificateTrust) {
const mock = createMockSession();
installScopedCertificateVerifier(mock.session, trust);
return mock;
}

it('allows an exact fingerprint match', () => {
const trust: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: 'AA:BB:CC' };
const mock = createScopedFixture(trust);

expect(mock.verify('backend.example', 'AA:BB:CC')).toBe(0);
});

it('rejects a fingerprint mismatch', () => {
const trust: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: 'AA:BB:CC' };
const mock = createScopedFixture(trust);

expect(mock.verify('backend.example', 'DD:EE:FF')).toBe(-2);
});

it('TOFU-learns the fingerprint on first connection and pins it', () => {
const trust: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: null };
const mock = createScopedFixture(trust);

expect(mock.verify('backend.example', 'AA:BB:CC')).toBe(0);
expect(trust.fingerprint).toBe('AA:BB:CC');
expect(mock.verify('backend.example', 'AA:BB:CC')).toBe(0);
expect(mock.verify('backend.example', 'DD:EE:FF')).toBe(-2);
});

it('delegates unrelated hostnames to Chromium default', () => {
const trust: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: 'AA:BB:CC' };
const mock = createScopedFixture(trust);

expect(mock.verify('other.example', 'AA:BB:CC')).toBe(-3);
});

it('does not allow one window trust to authorize another window on same hostname', () => {
const trustA: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: 'AA:BB:CC' };
const trustB: ScopedCertificateTrust = { hostname: 'backend.example', fingerprint: 'DD:EE:FF' };
const sessionA = createScopedFixture(trustA);
const sessionB = createScopedFixture(trustB);

expect(sessionA.verify('backend.example', 'AA:BB:CC')).toBe(0);
expect(sessionA.verify('backend.example', 'DD:EE:FF')).toBe(-2);
expect(sessionB.verify('backend.example', 'DD:EE:FF')).toBe(0);
expect(sessionB.verify('backend.example', 'AA:BB:CC')).toBe(-2);
});
});
37 changes: 37 additions & 0 deletions ui/desktop/src/backendCertificateVerifier.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { Buffer } from 'node:buffer';
import type { Session } from 'electron';

export interface BackendCertificateTrustVerifier {
has(hostname: string): boolean;
verify(hostname: string, fingerprint: string): boolean;
}

export interface ScopedCertificateTrust {
hostname: string;
fingerprint: string | null;
}

type CertificateVerifierSession = Pick<Session, 'setCertificateVerifyProc'>;

export function normalizeFingerprint(fp: string): string {
if (fp.startsWith('sha256/')) {
const b64 = fp.slice('sha256/'.length);
const buf = Buffer.from(b64, 'base64');
return Array.from(buf)
.map((b) => b.toString(16).padStart(2, '0'))
.join(':')
.toUpperCase();
}
return fp.toUpperCase();
}

export function installBackendCertificateVerifiers(
targetSessions: CertificateVerifierSession[],
trustVerifier: BackendCertificateTrustVerifier
Expand All @@ -23,3 +41,22 @@ export function installBackendCertificateVerifiers(
});
}
}

export function installScopedCertificateVerifier(
targetSession: CertificateVerifierSession,
trust: ScopedCertificateTrust
): void {
targetSession.setCertificateVerifyProc((request, callback) => {
if (request.hostname.toLowerCase() !== trust.hostname) {
callback(-3);
return;
}
const fp = normalizeFingerprint(request.certificate.fingerprint);
if (trust.fingerprint === null) {
trust.fingerprint = fp;
callback(0);
return;
}
callback(trust.fingerprint === fp ? 0 : -2);
});
}
7 changes: 5 additions & 2 deletions ui/desktop/src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ export default function ChatInput({
const textAreaRef = inputRef || internalTextAreaRef;
const timeoutRefsRef = useRef<Set<ReturnType<typeof setTimeout>>>(new Set());

useEffect(() => {
LocalMessageStorage.initialize();
}, []);

useEffect(() => {
// The draft is restored here rather than through `initialValue`, because this
// effect also runs on mount and would overwrite a value seeded into `useState`.
Expand Down Expand Up @@ -996,8 +1000,7 @@ export default function ChatInput({

evt.preventDefault();

// Get global history once to avoid multiple calls
const globalHistory = LocalMessageStorage.getRecentMessages() || [];
const globalHistory = LocalMessageStorage.getRecentMessages();

// Save current input if we're just starting to navigate history
if (historyIndex === -1) {
Expand Down
5 changes: 3 additions & 2 deletions ui/desktop/src/components/Layout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ const AppLayoutContent: React.FC<AppLayoutContentProps> = ({ activeSessions, liv
useEffect(() => {
const handleMouseMove = (e: MouseEvent) => {
if (!isResizing.current) return;
setNavWidth(startWidth.current + (e.clientX - startX.current));
setNavWidth(startWidth.current + (e.clientX - startX.current), false);
};
const handleMouseUp = () => {
const handleMouseUp = (e: MouseEvent) => {
if (isResizing.current) {
isResizing.current = false;
setIsDragging(false);
setNavWidth(startWidth.current + (e.clientX - startX.current), true);
}
};
window.addEventListener('mousemove', handleMouseMove);
Expand Down
14 changes: 8 additions & 6 deletions ui/desktop/src/components/Layout/NavigationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface NavigationContextValue {
isNavExpanded: boolean;
setIsNavExpanded: (expanded: boolean) => void;
navWidth: number;
setNavWidth: (width: number) => void;
setNavWidth: (width: number, persist: boolean) => void;
}

const NavigationContext = createContext<NavigationContextValue | null>(null);
Expand All @@ -46,17 +46,17 @@ interface NavigationProviderProps {

export const NavigationProvider: React.FC<NavigationProviderProps> = ({ children }) => {
const [isNavExpanded, setIsNavExpandedState] = useState<boolean>(() => {
const stored = localStorage.getItem('navigation_expanded');
const stored = window.electron.getRendererStorage('navigation_expanded');
return stored !== 'false';
});

const setIsNavExpanded = useCallback((expanded: boolean) => {
setIsNavExpandedState(expanded);
localStorage.setItem('navigation_expanded', String(expanded));
window.electron.setRendererStorage('navigation_expanded', String(expanded));
}, []);

const [navWidth, setNavWidthState] = useState<number>(() => {
const stored = localStorage.getItem('navigation_width');
const stored = window.electron.getRendererStorage('navigation_width');
if (stored) {
const parsed = parseInt(stored, 10);
if (!isNaN(parsed) && parsed >= MIN_NAV_WIDTH && parsed <= MAX_NAV_WIDTH) {
Expand All @@ -66,10 +66,12 @@ export const NavigationProvider: React.FC<NavigationProviderProps> = ({ children
return NAV_DIMENSIONS.NAV_WIDTH;
});

const setNavWidth = useCallback((width: number) => {
const setNavWidth = useCallback((width: number, persist: boolean) => {
const clamped = Math.min(MAX_NAV_WIDTH, Math.max(MIN_NAV_WIDTH, width));
setNavWidthState(clamped);
localStorage.setItem('navigation_width', String(clamped));
if (persist) {
window.electron.setRendererStorage('navigation_width', String(clamped));
}
}, []);

const isNavExpandedRef = useRef(isNavExpanded);
Expand Down
4 changes: 2 additions & 2 deletions ui/desktop/src/components/sessions/SessionListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
const [sessionToDelete, setSessionToDelete] = useState<SessionListItem | null>(null);

const [includeAcpSessions, setIncludeAcpSessions] = useState(
() => localStorage.getItem(INCLUDE_ACP_SESSIONS_KEY) === 'true'
() => window.electron.getRendererStorage(INCLUDE_ACP_SESSIONS_KEY) === 'true'
);
const includeAcpSessionsRef = useRef(includeAcpSessions);
includeAcpSessionsRef.current = includeAcpSessions;
Expand Down Expand Up @@ -494,7 +494,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
}, []);

const handleIncludeAcpSessionsChange = useCallback((checked: boolean) => {
localStorage.setItem(INCLUDE_ACP_SESSIONS_KEY, String(checked));
window.electron.setRendererStorage(INCLUDE_ACP_SESSIONS_KEY, String(checked));
setIncludeAcpSessions(checked);
}, []);

Expand Down
Loading
Loading