misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Firefox: a VPN add-on's proxy goes with downloads taken before the file dialog; loopback skips the proxy (#295)
Ahmed Nefzaoui855661040fd2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 92de8be4..38f09a99 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -381,7 +381,8 @@ choose. And Linux, checked on a real desktop with every change.Vivaldi can't make that permission optional, so their extension has it from the install; Chromecounts it under the access to every site the extension already has, so the update asks fornothing new. There the extension reads the browser's proxy settings: the server for the- download's scheme (honouring their bypass list), or their auto-config script.+ download's scheme (honouring their bypass list), or their auto-config script. Addresses on+ this computer (localhost, 127.0.0.1) go straight to it, as the browser sends them.- **Zen, Helium and other browsers built on Firefox or Chromium** ([#41](https://github.com/anefzaoui/misterdownloadmanager/issues/41)):the extension reaches MDM in them, also when one is the only browser on Linux or macOS (Zenreads Firefox's folder, which MDM now creates; Helium its own). **Add Mister Download Managerdiff --git a/ROADMAP.md b/ROADMAP.mdindex 9f7d961b..c38b20eb 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -167,7 +167,9 @@ Everything below ships together, in the next release.without making it; store packages and theme windows are checked there too (part of[#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164))- ✅ Firefox: reading the browser's proxy (#42) is an opt-in, a switch in the extension's popup, so- the extension's update asks for no new permission+ the extension's update asks for no new permission; a VPN add-on's proxy goes with the downloads+ taken before Firefox's file dialog too, and addresses on this computer skip the proxy, as in+ Firefox- ✅ Chrome and the other Chromium browsers: downloads go through the browser's proxy or VPNextension too (#42), with the same switch, off as installed: a fixed server for each scheme andits bypass list, or an auto-config scriptdiff --git a/extension/background.js b/extension/background.jsindex f7a29350..69788513 100644--- a/extension/background.js+++ b/extension/background.js@@ -1025,15 +1025,16 @@ if (PROXY_DECLARED && ext.webRequest && ext.webRequest.onAuthRequired) {// Not offered here: no login is noticed.}}+// Firefox: the proxy a request went through, kept for its hand-over. Noted as its response+// starts, and from its answer's headers when the extension takes the download there (#208): that+// request is cancelled, so it never starts.+function noteProxy(d) {+ if (!proxyAllowed || !d.proxyInfo || d.proxyInfo.type === "direct") return;+ forget(proxyUsed, 120000);+ proxyUsed.set(d.url, { info: d.proxyInfo, at: Date.now() });+}if (PROXY_DECLARED && FIREFOX && ext.webRequest && ext.webRequest.onResponseStarted) {- ext.webRequest.onResponseStarted.addListener(- (d) => {- if (!proxyAllowed || !d.proxyInfo || d.proxyInfo.type === "direct") return;- forget(proxyUsed, 120000);- proxyUsed.set(d.url, { info: d.proxyInfo, at: Date.now() });- },- { urls: ["<all_urls>"] },- );+ ext.webRequest.onResponseStarted.addListener(noteProxy, { urls: ["<all_urls>"] });}const hostPort = (host, port) => `${String(host).includes(":") ? `[${host}]` : host}:${port}`;@@ -1109,6 +1110,13 @@ async function pacText(url) {}}+// Firefox never sends loopback addresses through its proxy settings' proxy+// (network.proxy.allow_hijacking_localhost, off by default): localhost and its names, 127.0.0.0/8, ::1.+function firefoxLoopback(u) {+ const host = u.hostname.toLowerCase().replace(/^\[|\]$/g, "");+ return host === "localhost" || host.endsWith(".localhost") || host === "::1" || /^127(\.\d{1,3}){3}$/.test(host);+}+// What the app needs to download `url` through the browser's proxy: {} when it uses none (or// the system's, which the app reads itself), and {} unless the user switched it on (above).async function browserProxy(url, incognito) {@@ -1158,6 +1166,7 @@ async function browserProxy(url, incognito) {}// Firefox: {proxyType, http, ssl, socks, socksVersion, proxyDNS, autoConfigUrl, passthrough}.if (v.proxyType === "manual") {+ if (firefoxLoopback(u)) return {};if (String(v.passthrough || "").split(/[,\s]+/).some((b) => bypassed(b, u))) return {};const pick = (hp) => {const m = /^\[?([^\]]+?)\]?:(\d+)$/.exec(String(hp || "").trim());@@ -1534,6 +1543,10 @@ async function headersReceived(d) {incognito: Boolean(d.incognito),cookieStoreId: d.cookieStoreId,};+ if (PROXY_DECLARED) {+ await proxyChecked;+ noteProxy(d);+ }const first = firstUrl(item);forget(decided, 120000);decided.set(d.url, { at: Date.now() });diff --git a/tools/extension/test.mjs b/tools/extension/test.mjsindex 0c6b4c0d..9ac8fbd2 100644--- a/tools/extension/test.mjs+++ b/tools/extension/test.mjs@@ -1381,6 +1381,34 @@ const ask = (listeners) => (m, sender) => new Promise((r) => listeners.message(massert.deepEqual(steps(calls), []);ok("#208 Firefox: a download caught from its answer, before the browser's dialog");}+// A download taken from its answer (#208) is cancelled, so its response never starts: the proxy a+// VPN add-on chose for it (proxy.onRequest, in the answer's proxyInfo) still goes with it.+{+ const { api, calls, listeners } = fakeApi({ firefox: true, proxyGranted: true });+ load(api, true);+ await settle();+ const res = await held(+ listeners,+ answer("https://dl.test/vpn.zip", { "Content-Type": "application/zip", "Content-Disposition": "attachment" }, { proxyInfo: { type: "socks", host: "10.8.0.1", port: 1080, proxyDNS: true } }),+ );+ assert.deepEqual(res, { cancel: true });+ assert.deepEqual([natives(calls)[0].proxy, natives(calls)[0].proxyLogin], ["socks5h://10.8.0.1:1080", undefined]);+ ok("#208 Firefox: a download taken from its answer keeps its request's proxy (a VPN add-on's)");+}+// Firefox's own proxy settings never cover loopback addresses (allow_hijacking_localhost is off):+// nothing is sent for them, the proxy for anything else.+{+ const settings = { proxyType: "manual", http: "10.0.0.9:3128", httpProxyAll: true, passthrough: "" };+ const { api, calls, listeners } = fakeApi({ firefox: true, proxyGranted: true, proxy: settings });+ api.proxy.settings.get = async () => ({ value: settings });+ load(api, true);+ await settle();+ const urls = ["http://127.0.0.1:8231/a.zip", "http://localhost/b.zip", "http://[::1]/c.zip", "http://127.9.9.9/d.zip", "https://x.test/e.zip"];+ urls.forEach((url, i) => listeners.created({ id: 60 + i, url, filename: `C:\dl\f${i}.zip` }));+ await settle();+ assert.deepEqual(natives(calls).map((m) => m.proxy), [undefined, undefined, undefined, undefined, "http://10.0.0.9:3128"]);+ ok("Firefox: loopback addresses skip its proxy settings' proxy, as Firefox itself does");+}// A type the app doesn't take: the browser goes on (its dialog shows), MDM's log hears why once,// and the download after the dialog isn't paused or asked again.{