diff --git a/src/main/browser/browser-cookie-import.test.ts b/src/main/browser/browser-cookie-import.test.ts index 55fae27c9..657215a6f 100644 --- a/src/main/browser/browser-cookie-import.test.ts +++ b/src/main/browser/browser-cookie-import.test.ts @@ -223,6 +223,35 @@ describe('importCookiesFromFile', () => { expect(firstCall.sameSite).toBe('lax') }) + it('sets __Host- cookies host-only so Chromium does not reject them', async () => { + const filePath = writeCookieFile([ + { + domain: 'github.com', + name: '__Host-user_session_same_site', + value: 'sess', + path: '/account', + secure: true, + httpOnly: true, + sameSite: 'lax' + }, + { domain: '.github.com', name: '_gh_sess', value: 'abc', path: '/settings', secure: true } + ]) + + const result = await importCookiesFromFile(filePath, 'persist:test') + expect(result.ok).toBe(true) + + const hostCall = cookiesSetMock.mock.calls + .map((c) => c[0]) + .find((c) => c.name === '__Host-user_session_same_site') + // __Host- prefix requires no Domain attribute and path=/, or Chromium drops it. + expect(hostCall).not.toHaveProperty('domain') + expect(hostCall.path).toBe('/') + + const normalCall = cookiesSetMock.mock.calls.map((c) => c[0]).find((c) => c.name === '_gh_sess') + expect(normalCall.domain).toBe('.github.com') + expect(normalCall.path).toBe('/settings') + }) + it('rejects non-JSON files', async () => { const filePath = join(tmpDir, 'bad.json') writeFileSync(filePath, 'not json at all') diff --git a/src/main/browser/browser-cookie-import.ts b/src/main/browser/browser-cookie-import.ts index 22b891cd2..23bdd2487 100644 --- a/src/main/browser/browser-cookie-import.ts +++ b/src/main/browser/browser-cookie-import.ts @@ -567,12 +567,14 @@ async function importValidatedCookies( for (const cookie of cookies) { try { + // Why: Chromium rejects __Host- cookies unless they omit domain and use path=/. + const isHostPrefixed = cookie.name.startsWith('__Host-') await targetSession.cookies.set({ url: cookie.url, name: cookie.name, value: stripNonPrintable(cookie.value), - domain: cookie.domain, - path: cookie.path, + ...(isHostPrefixed ? {} : { domain: cookie.domain }), + path: isHostPrefixed ? '/' : cookie.path, secure: cookie.secure, httpOnly: cookie.httpOnly, sameSite: cookie.sameSite,