mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-06 01:17:48 +00:00
fix(extension): harden desktop handoff
This commit is contained in:
+3
-1
@@ -545,7 +545,9 @@ function App() {
|
||||
});
|
||||
|
||||
const unlistenExtension = listen('extension-add-download', (event) => {
|
||||
useDownloadStore.getState().handleExtensionDownload(event.payload);
|
||||
useDownloadStore.getState().handleExtensionDownload(event.payload).catch(error => {
|
||||
console.error('Failed to handle browser extension download:', error);
|
||||
});
|
||||
});
|
||||
const unlistenDeepLink = listen('deep-link-add-download', (event) => {
|
||||
useDownloadStore.getState().openAddModalWithUrls(event.payload);
|
||||
|
||||
@@ -46,17 +46,17 @@ export const KeychainPermissionModal: React.FC = () => {
|
||||
<div className="p-2 bg-blue-500/10 rounded-full flex items-center justify-center">
|
||||
<KeyRound size={20} className="text-blue-500" />
|
||||
</div>
|
||||
<h2 className="text-lg font-semibold text-text-primary m-0">Keychain Access Needed</h2>
|
||||
<h2 className="text-lg font-semibold text-text-primary m-0">Credential Storage Access Needed</h2>
|
||||
</div>
|
||||
|
||||
<div className="px-5 py-6 flex-1 text-sm text-text-secondary leading-relaxed space-y-4">
|
||||
<p>
|
||||
Firelink uses a browser extension to seamlessly capture downloads.
|
||||
To securely store the pairing token that connects the app and the extension,
|
||||
we need access to the macOS Keychain.
|
||||
Firelink uses the browser extension to seamlessly capture downloads.
|
||||
To securely store the pairing token that connects the app and the extension,
|
||||
we need access to this system's credential store.
|
||||
</p>
|
||||
<p>
|
||||
<strong>Note:</strong> Firelink only requests access to its own dedicated entry in the Keychain. It cannot and will not access any other passwords or Keychain items on your system.
|
||||
<strong>Note:</strong> Firelink only requests access to its own dedicated credential entry. It cannot and will not access other saved passwords or credential items on your system.
|
||||
</p>
|
||||
|
||||
{error && (
|
||||
|
||||
@@ -1061,9 +1061,9 @@ className="app-button px-3 py-1.5 text-[12px] flex items-center gap-1.5 disabled
|
||||
<Check size={16} strokeWidth={2.5} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<h4 className="text-sm font-semibold text-green-500 m-0">Keychain Access Granted</h4>
|
||||
<h4 className="text-sm font-semibold text-green-500 m-0">Credential Storage Available</h4>
|
||||
<p className="text-xs text-text-secondary m-0 mt-0.5">
|
||||
Your pairing token is securely saved and will persist across restarts.
|
||||
Your pairing token is securely saved in this system's credential store and will persist across restarts.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1071,16 +1071,16 @@ className="app-button px-3 py-1.5 text-[12px] flex items-center gap-1.5 disabled
|
||||
<div className="bg-orange-500/10 border border-orange-500/20 rounded-lg p-4 flex items-start gap-3">
|
||||
<ShieldAlert className="w-5 h-5 text-orange-500 flex-shrink-0 mt-0.5" />
|
||||
<div className="flex-1">
|
||||
<h4 className="text-sm font-semibold text-text-primary mb-1">Keychain Access Needed</h4>
|
||||
<h4 className="text-sm font-semibold text-text-primary mb-1">Credential Storage Needed</h4>
|
||||
<p className="text-xs text-text-secondary mb-3">
|
||||
Firelink needs macOS Keychain access to securely save your pairing token across app restarts.
|
||||
Firelink needs access to this system's credential store to securely save your pairing token across app restarts.
|
||||
Currently, your extension will only stay connected for this session.
|
||||
</p>
|
||||
<button
|
||||
onClick={() => settings.setShowKeychainModal(true)}
|
||||
className="px-4 py-1.5 rounded-md text-xs font-medium transition-colors bg-accent text-white hover:bg-accent/90 shadow-sm"
|
||||
>
|
||||
Grant Keychain Access
|
||||
Grant Credential Access
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -55,6 +55,12 @@ describe('useDownloadStore', () => {
|
||||
downloads: [],
|
||||
backendRegisteredIds: new Set(),
|
||||
pendingOrder: [],
|
||||
isAddModalOpen: false,
|
||||
pendingAddUrls: '',
|
||||
pendingAddReferer: '',
|
||||
pendingAddFilename: '',
|
||||
pendingAddHeaders: '',
|
||||
pendingAddCookies: '',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -367,8 +373,8 @@ describe('useDownloadStore', () => {
|
||||
)?.[1] as any).item.queue_id).toBe('queue-a');
|
||||
});
|
||||
|
||||
it('preserves extension request headers and cookies for the Add modal', () => {
|
||||
useDownloadStore.getState().handleExtensionDownload({
|
||||
it('preserves extension request headers and cookies for the Add modal', async () => {
|
||||
await useDownloadStore.getState().handleExtensionDownload({
|
||||
urls: ['https://example.com/file.bin'],
|
||||
referer: 'https://example.com/page',
|
||||
silent: false,
|
||||
@@ -382,7 +388,45 @@ describe('useDownloadStore', () => {
|
||||
expect(state.pendingAddUrls).toBe('https://example.com/file.bin');
|
||||
expect(state.pendingAddReferer).toBe('https://example.com/page');
|
||||
expect(state.pendingAddFilename).toBe('file.bin');
|
||||
expect(state.pendingAddHeaders).toBe('X-Test: value');
|
||||
expect(state.pendingAddCookies).toBe('session=secret');
|
||||
expect(state.pendingAddHeaders).toBe('X-Test: value');
|
||||
expect(state.pendingAddCookies).toBe('session=secret');
|
||||
});
|
||||
|
||||
it('starts silent extension captures through backend queue', async () => {
|
||||
vi.mocked(ipc.invokeCommand).mockImplementation(async (command: string) => {
|
||||
if (command === 'get_pending_order') return ['silent-id'];
|
||||
return undefined;
|
||||
});
|
||||
vi.spyOn(crypto, 'randomUUID').mockReturnValueOnce('silent-id' as `${string}-${string}-${string}-${string}-${string}`);
|
||||
|
||||
await useDownloadStore.getState().handleExtensionDownload({
|
||||
urls: ['https://example.com/downloads/report.pdf'],
|
||||
referer: 'https://example.com/page',
|
||||
silent: true,
|
||||
filename: 'report.pdf',
|
||||
headers: 'User-Agent: Test',
|
||||
cookies: 'session=secret'
|
||||
});
|
||||
|
||||
const state = useDownloadStore.getState();
|
||||
expect(state.isAddModalOpen).toBe(false);
|
||||
expect(state.downloads[0]).toEqual(expect.objectContaining({
|
||||
id: 'silent-id',
|
||||
url: 'https://example.com/downloads/report.pdf',
|
||||
fileName: 'report.pdf',
|
||||
category: 'Documents',
|
||||
queueId: '00000000-0000-0000-0000-000000000001',
|
||||
hasBeenDispatched: true
|
||||
}));
|
||||
expect(ipc.invokeCommand).toHaveBeenCalledWith(
|
||||
'enqueue_download',
|
||||
expect.objectContaining({
|
||||
item: expect.objectContaining({
|
||||
id: 'silent-id',
|
||||
headers: 'User-Agent: Test',
|
||||
cookies: 'session=secret'
|
||||
})
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { DownloadStatus } from '../bindings/DownloadStatus';
|
||||
import type { ExtensionDownload } from '../bindings/ExtensionDownload';
|
||||
import type { Queue } from '../bindings/Queue';
|
||||
import { useSettingsStore } from './useSettingsStore';
|
||||
import { categoryForFileName, isActiveDownloadStatus, normalizeSpeedLimitForBackend, redactDownloadForPersistence } from '../utils/downloads';
|
||||
import { canonicalizeDownloadFileName, categoryForFileName, isActiveDownloadStatus, normalizeSpeedLimitForBackend, redactDownloadForPersistence } from '../utils/downloads';
|
||||
import {
|
||||
resolveCategoryDestination
|
||||
} from '../utils/downloadLocations';
|
||||
@@ -125,6 +125,16 @@ export const getSiteLogin = (url: string, settings: ReturnType<typeof useSetting
|
||||
return null;
|
||||
};
|
||||
|
||||
const suggestedFileNameFromUrl = (rawUrl: string): string => {
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
const lastSegment = decodeURIComponent(url.pathname.split('/').filter(Boolean).pop() || '');
|
||||
return lastSegment || 'download';
|
||||
} catch {
|
||||
return 'download';
|
||||
}
|
||||
};
|
||||
|
||||
const syncSystemIntegrations = () => {
|
||||
const settings = useSettingsStore.getState();
|
||||
const activeCount = useDownloadStore.getState().downloads.filter(d => d.status === 'downloading').length;
|
||||
@@ -192,7 +202,7 @@ interface DownloadState {
|
||||
headers?: string | null,
|
||||
cookies?: string | null
|
||||
) => void;
|
||||
handleExtensionDownload: (request: ExtensionDownloadRequest) => void;
|
||||
handleExtensionDownload: (request: ExtensionDownloadRequest) => Promise<void>;
|
||||
deleteModalState: DeleteModalState;
|
||||
openDeleteModal: (downloadIds?: string | string[]) => void;
|
||||
closeDeleteModal: () => void;
|
||||
@@ -302,10 +312,28 @@ export const useDownloadStore = create<DownloadState>((set, get) => ({
|
||||
pendingAddCookies: cookies?.trim() || state.pendingAddCookies || ''
|
||||
};
|
||||
}),
|
||||
handleExtensionDownload: (request) => {
|
||||
handleExtensionDownload: async (request) => {
|
||||
const urls = [...new Set(request.urls.map(url => url.trim()).filter(Boolean))];
|
||||
if (urls.length === 0) return;
|
||||
|
||||
if (request.silent) {
|
||||
for (const url of urls) {
|
||||
const filename = canonicalizeDownloadFileName(
|
||||
urls.length === 1 && request.filename ? request.filename : suggestedFileNameFromUrl(url)
|
||||
);
|
||||
await get().addDownload({
|
||||
id: crypto.randomUUID(),
|
||||
url,
|
||||
fileName: filename,
|
||||
category: categoryForFileName(filename),
|
||||
dateAdded: new Date().toISOString(),
|
||||
headers: request.headers?.trim() || undefined,
|
||||
cookies: urls.length === 1 ? request.cookies?.trim() || undefined : undefined,
|
||||
}, { type: 'start-now' });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
get().openAddModalWithUrls(
|
||||
urls.join('\n'),
|
||||
request.referer,
|
||||
|
||||
Reference in New Issue
Block a user