Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Fix/603 colab runtime proxy only (#729)

muhammadbilaloffical9-lab0612aa8a444c
diff --git a/ROADMAP.md b/ROADMAP.md
index 4c50557a..2e4e2508 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -710,6 +710,7 @@ These ship in a later version, when they're ready.
[#345](https://github.com/anefzaoui/misterdownloadmanager/issues/345)): fix in review
- πŸ”„ A page that starts a download by script being saved instead of the file
([#374](https://github.com/anefzaoui/misterdownloadmanager/issues/374)): fix in review
+- πŸ”„ Google Colab: only tokenized runtime-proxy transfers stay with the browser; ordinary notebook links remain capturable ([#603](https://github.com/anefzaoui/misterdownloadmanager/issues/603)): fix in review
- πŸ”„ A gofile share link saving a web page instead of the file
([#346](https://github.com/anefzaoui/misterdownloadmanager/issues/346)): fix in review
- πŸ”„ A server's refusal page saved under the document's name and shown as complete, where the
diff --git a/extension/background.js b/extension/background.js
index 0520b977..0f41bb91 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -1277,6 +1277,26 @@ async function handOff(d) {
return native(message);
}
+// Colab's runtime proxy uses an ephemeral token tied to the browser's partitioned session.
+// Only the actual proxy transfer URL is left to the browser: a normal file linked from a Colab
+// notebook must still be capturable by MDM (#603).
+function colabRuntimeProxy(...urls) {
+ return urls.some((value) => {
+ if (!value) return false;
+ try {
+ const u = new URL(value);
+ const host = u.hostname.toLowerCase();
+ const proxyHost =
+ host === "prod.r.colab.dev"
+ || host.endsWith(".prod.r.colab.dev")
+ || /(?:^|[-.])colab\.googleusercontent\.com$/.test(host);
+ return proxyHost && u.searchParams.has("colab-runtime-proxy-token");
+ } catch {
+ return false;
+ }
+ });
+}
+
// The file name to offer the app the download under (`{name}`), or why Options leave it to
// the browser (`{left, name}`), or null: the browser keeps it and there is nothing to say (not a
// web address, paused, Alt held, a form that can't be posted again, MDM not reached).
@@ -1288,6 +1308,7 @@ async function candidate(item, url) {
if (bypass.has(item.url) || bypass.has(url)) return null;
const first = firstUrl(item);
if (bypass.has(first) || postOf(first) === null) return null; // Alt; a form not to post again
+ if (colabRuntimeProxy(first, url)) return null;
const r = await currentRules();
if (!r) return null;
const name = (item.filename || "").split(/[\\/]/).pop() || url.split(/[?#]/)[0].split("/").pop() || "";
diff --git a/tools/extension/test.mjs b/tools/extension/test.mjs
index 9f305979..302dc5c9 100644
--- a/tools/extension/test.mjs
+++ b/tools/extension/test.mjs
@@ -2085,6 +2085,122 @@ const ask = (listeners) => (m, sender) => new Promise((r) => listeners.message(m
assert.equal(listeners.headersReceived, undefined);
ok("#208 Chromium: answers aren't held");
}
+// #603: only a tokenized Colab runtime-proxy transfer stays with the browser. A normal
+// download linked from a Colab notebook is still offered to MDM.
+{
+ const { api, calls, listeners } = fakeApi({ firefox: false });
+ load(api, false);
+ await settle();
+ let suggested;
+ listeners.determining(
+ {
+ id: 91,
+ url: "https://us-west1-colab.googleusercontent.com/files/out.zip?colab-runtime-proxy-token=secret",
+ finalUrl: "https://us-west1-colab.googleusercontent.com/files/out.zip?colab-runtime-proxy-token=secret",
+ referrer: "https://colab.research.google.com/drive/abc",
+ filename: "out.zip",
+ totalBytes: 1024,
+ mime: "application/zip",
+ },
+ (value) => (suggested = value),
+ );
+ await settle();
+ assert.ok(suggested, "the browser keeps the authenticated runtime-proxy download");
+ assert.equal(natives(calls).length, 0);
+ ok("#603 Chromium: tokenized Colab runtime-proxy download stays in the browser");
+}
+{
+ const { api, calls, listeners } = fakeApi({ firefox: false });
+ load(api, false);
+ await settle();
+ listeners.determining(
+ {
+ id: 92,
+ url: "https://github.com/example/data/archive/refs/heads/main.zip",
+ finalUrl: "https://github.com/example/data/archive/refs/heads/main.zip",
+ referrer: "https://colab.research.google.com/drive/abc",
+ filename: "data.zip",
+ totalBytes: 4096,
+ mime: "application/zip",
+ },
+ () => {},
+ );
+ await settle();
+ assert.equal(natives(calls).length, 1, "ordinary notebook links remain capturable");
+ ok("#603 Chromium: a GitHub file linked from Colab is still handed to MDM");
+}
+{
+ const { api, calls, listeners } = fakeApi({ firefox: true });
+ load(api, true);
+ await settle();
+ const url = "https://us-west1.prod.r.colab.dev/files/out.zip?colab-runtime-proxy-token=secret";
+ listeners.beforeSendHeaders({
+ requestId: "r-colab",
+ method: "GET",
+ type: "main_frame",
+ url,
+ originUrl: "https://colab.research.google.com/drive/abc",
+ requestHeaders: [],
+ });
+ const response = await held(
+ listeners,
+ answer(
+ url,
+ {
+ "Content-Type": "application/zip",
+ "Content-Disposition": "attachment; filename=out.zip",
+ "Content-Length": "1024",
+ },
+ { requestId: "r-colab" },
+ ),
+ );
+ assert.deepEqual(response, {});
+ assert.equal(natives(calls).length, 0, "Firefox leaves the authenticated transfer to the browser");
+ ok("#603 Firefox: tokenized Colab runtime-proxy download stays in the browser");
+}
+
+// A token alone is not enough: unrelated hosts must still be captured.
+{
+ const { api, calls, listeners } = fakeApi({ firefox: false });
+ load(api, false);
+ await settle();
+ listeners.determining(
+ {
+ id: 93,
+ url: "https://downloads.example/data.zip?colab-runtime-proxy-token=not-colab",
+ finalUrl: "https://downloads.example/data.zip?colab-runtime-proxy-token=not-colab",
+ referrer: "https://colab.research.google.com/drive/abc",
+ filename: "data.zip",
+ totalBytes: 4096,
+ mime: "application/zip",
+ },
+ () => {},
+ );
+ await settle();
+ assert.equal(natives(calls).length, 1, "a token on a non-proxy host must not bypass MDM");
+ ok("#603 Chromium: tokenized non-Colab URLs remain capturable");
+}
+{
+ const { api, calls, listeners } = fakeApi({ firefox: false });
+ load(api, false);
+ await settle();
+ listeners.determining(
+ {
+ id: 94,
+ url: "https://prod.r.colab.dev/files/out.zip",
+ finalUrl: "https://prod.r.colab.dev/files/out.zip",
+ referrer: "https://colab.research.google.com/drive/abc",
+ filename: "out.zip",
+ totalBytes: 4096,
+ mime: "application/zip",
+ },
+ () => {},
+ );
+ await settle();
+ assert.equal(natives(calls).length, 1, "a proxy host without its token must not bypass MDM");
+ ok("#603 Chromium: an un-tokenized Colab host remains capturable");
+}
+
// The manifests (#42): "proxy" optional in Firefox's, required in Chrome's (it can't be optional
// there); the popup's switch: the permission in Firefox, the extension's own setting in Chrome.
{