Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
Harden main-process security and validate persisted network prefs
Anmol Kapilb1a39ebb2313
diff --git a/src/main/index.ts b/src/main/index.tsindex c5c564c..111f4fb 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -75,8 +75,7 @@ function createWindow(): void {? { titleBarStyle: 'hiddenInset', trafficLightPosition: { x: 16, y: 16 } }: {}),webPreferences: {- preload: join(__dirname, '../preload/index.js'),- sandbox: false+ preload: join(__dirname, '../preload/index.js')}})@@ -89,7 +88,10 @@ function createWindow(): void {})mainWindow.webContents.setWindowOpenHandler((details) => {- shell.openExternal(details.url)+ // Only hand http(s) links to the OS shell — an arbitrary scheme (e.g. a custom protocol+ // handler) reaching shell.openExternal is a known Electron risk if this ever fires with+ // attacker- or server-influenced data.+ if (/^https?:/i.test(details.url)) void shell.openExternal(details.url)return { action: 'deny' }})diff --git a/src/main/network/preferences.ts b/src/main/network/preferences.tsindex 73d0373..4bcaed0 100644--- a/src/main/network/preferences.ts+++ b/src/main/network/preferences.ts@@ -7,10 +7,29 @@ function preferencesPath(): string {return join(app.getPath('userData'), 'network-preferences.json')}+/** Trusts nothing past "this is valid JSON" — a hand-edited or partially-migrated file could have+ * any shape on disk. Keeps only string customName/colorId fields (what every reader downstream+ * assumes, e.g. NetworkEditPopover's `customName?.trim()`) and drops anything else, entry by+ * entry, rather than discarding the whole file over one bad entry. */+function sanitizeNetworkPreferences(parsed: unknown): NetworkPreferences {+ if (typeof parsed !== 'object' || parsed === null) return {}++ const result: NetworkPreferences = {}+ for (const [id, value] of Object.entries(parsed as Record<string, unknown>)) {+ if (typeof value !== 'object' || value === null) continue+ const { customName, colorId } = value as Record<string, unknown>+ const preference: NetworkPreference = {}+ if (typeof customName === 'string') preference.customName = customName+ if (typeof colorId === 'string') preference.colorId = colorId+ if (preference.customName || preference.colorId) result[id] = preference+ }+ return result+}+export async function loadNetworkPreferences(): Promise<NetworkPreferences> {try {const raw = await readFile(preferencesPath(), 'utf-8')- return JSON.parse(raw) as NetworkPreferences+ return sanitizeNetworkPreferences(JSON.parse(raw))} catch {// No file yet (first run) or it's unreadable/corrupt — either way, no saved prefs.return {}