Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
fix(chrome-extension): harden detection, security, and error handling
InstaZDLL09532cb7b69c
diff --git a/browser-extension/chrome/pages/error.html b/browser-extension/chrome/pages/error.htmlindex 1ccd51fa..d40c709c 100644--- a/browser-extension/chrome/pages/error.html+++ b/browser-extension/chrome/pages/error.html@@ -16,7 +16,7 @@<pre id="url" class="url"></pre><div class="actions"><a id="install-link" class="button primary" href="#" target="_blank" rel="noreferrer">Install OmniGet</a>- <a class="button" href="chrome://extensions">Open Chrome Extensions</a>+ <button id="open-extensions" class="button" type="button">Open Chrome Extensions</button></div></div></main>diff --git a/browser-extension/chrome/pages/error.js b/browser-extension/chrome/pages/error.jsindex c147ae7f..1b0c8ce5 100644--- a/browser-extension/chrome/pages/error.js+++ b/browser-extension/chrome/pages/error.js@@ -11,6 +11,8 @@ const detail = document.getElementById("detail");const urlNode = document.getElementById("url");const installLink = document.getElementById("install-link");+const openExtensionsBtn = document.getElementById("open-extensions");+const content = getContent(code);title.textContent = content.title;@@ -19,6 +21,10 @@ detail.textContent = message || content.detail;urlNode.textContent = url;installLink.href = installUrl;+openExtensionsBtn.addEventListener("click", () => {+ chrome.tabs.create({ url: "chrome://extensions" });+});+function getContent(errorCode) {switch (errorCode) {case "HOST_MISSING":diff --git a/browser-extension/chrome/src/background.js b/browser-extension/chrome/src/background.jsindex cb1237c1..ffba1fe7 100644--- a/browser-extension/chrome/src/background.js+++ b/browser-extension/chrome/src/background.js@@ -101,6 +101,7 @@ async function refreshTabAction(tabId, tab) {}try {+ // TODO: use chrome.i18n via _locales/ for multi-language tooltipsawait chrome.action.setTitle({tabId,title: supporteddiff --git a/browser-extension/chrome/src/detect.js b/browser-extension/chrome/src/detect.jsindex 4d6886be..22204295 100644--- a/browser-extension/chrome/src/detect.js+++ b/browser-extension/chrome/src/detect.js@@ -50,7 +50,7 @@ function detectPlatform(url) {if (matchesHost(host, "twitter.com") || matchesHost(host, "x.com") || matchesHost(host, "vxtwitter.com") || matchesHost(host, "fixvx.com")) return "twitter";if (matchesHost(host, "reddit.com") || host === "v.redd.it" || host === "redd.it") return "reddit";if (matchesHost(host, "twitch.tv")) return "twitch";- if (host === "pin.it" || host.includes("pinterest.")) return "pinterest";+ if (host === "pin.it" || isPinterestHost(host)) return "pinterest";if (host === "bsky.app" || host.endsWith(".bsky.app")) return "bluesky";if (host === "t.me" || matchesHost(host, "telegram.me") || matchesHost(host, "telegram.org")) return "telegram";if (matchesHost(host, "vimeo.com")) return "vimeo";@@ -112,6 +112,10 @@ function parseYouTube(url, segments) {return "playlist";}+ if ((segments[0] === "live" || segments[0] === "embed" || segments[0] === "v") && segments[1]) {+ return "video";+ }+if (segments[0] === "channel" ||segments[0] === "c" ||@@ -144,7 +148,12 @@ function parseTikTok(segments) {return "profile";}- return segments[0] ? "video" : "unknown";+ const tiktokNonVideo = ["explore", "foryou", "following", "live", "about", "legal", "safety", "transparency"];+ if (segments[0] && !tiktokNonVideo.includes(segments[0])) {+ return "video";+ }++ return "unknown";}function parseTwitter(segments) {@@ -181,7 +190,7 @@ function parseReddit(url, segments) {return segments[1] ? "profile" : "unknown";}- return segments[0] ? "video" : "unknown";+ return "unknown";}function parseTwitch(url, segments) {@@ -199,7 +208,12 @@ function parseTwitch(url, segments) {return "clip";}- return segments[0] && !["directory", "settings", "downloads"].includes(segments[0]) ? "profile" : "unknown";+ const twitchNonChannel = ["directory", "settings", "downloads", "jobs", "turbo", "store", "inventory", "wallet", "subscriptions", "friends", "prime"];+ if (segments[0] && !twitchNonChannel.includes(segments[0])) {+ return "video"; // live stream — downloadable via yt-dlp+ }++ return "unknown";}function parseHotmart(segments) {@@ -249,3 +263,7 @@ function parseBilibili(segments) {function matchesHost(host, domain) {return host === domain || host.endsWith(`.${domain}`);}++function isPinterestHost(host) {+ return /(?:^|\.)pinterest\.\w+(?:\.\w+)?$/.test(host);+}diff --git a/browser-extension/chrome/tests/detect.test.mjs b/browser-extension/chrome/tests/detect.test.mjsindex ce956494..e74aba45 100644--- a/browser-extension/chrome/tests/detect.test.mjs+++ b/browser-extension/chrome/tests/detect.test.mjs@@ -3,32 +3,323 @@ import assert from "node:assert/strict";import { detectSupportedMediaUrl } from "../src/detect.js";-test("flags direct YouTube watch pages as supported", () => {- const detected = detectSupportedMediaUrl("https://www.youtube.com/watch?v=abc123");- assert.equal(detected?.platform, "youtube");- assert.equal(detected?.contentType, "video");- assert.equal(detected?.supported, true);+// ── Helpers ──────────────────────────────────────────────────────────────++function assertSupported(url, platform, contentType) {+ const detected = detectSupportedMediaUrl(url);+ assert.equal(detected?.platform, platform, `platform for ${url}`);+ assert.equal(detected?.contentType, contentType, `contentType for ${url}`);+ assert.equal(detected?.supported, true, `expected supported for ${url}`);+}++function assertUnsupported(url, platform, contentType) {+ const detected = detectSupportedMediaUrl(url);+ assert.equal(detected?.platform, platform, `platform for ${url}`);+ assert.equal(detected?.contentType, contentType, `contentType for ${url}`);+ assert.equal(detected?.supported, false, `expected unsupported for ${url}`);+}++function assertNull(url) {+ assert.equal(detectSupportedMediaUrl(url), null, `expected null for ${url}`);+}++// ── Edge cases / invalid input ───────────────────────────────────────────++test("returns null for null/undefined/empty", () => {+ assertNull(null);+ assertNull(undefined);+ assertNull("");+});++test("returns null for non-http protocols", () => {+ assertNull("ftp://example.com/video.mp4");+ assertNull("file:///home/user/video.mp4");+ assertNull("magnet:?xt=urn:btih:abc");+});++test("returns null for malformed URLs", () => {+ assertNull("not a url at all");+ assertNull("http://");+});++test("returns null for unsupported sites", () => {+ assertNull("https://www.google.com/search?q=omniget");+ assertNull("https://github.com/tonhowtf/omniget");+ assertNull("https://example.com/video/123");+});++// ── YouTube ──────────────────────────────────────────────────────────────++test("YouTube: direct watch page", () => {+ assertSupported("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "youtube", "video");+});++test("YouTube: watch page with playlist param", () => {+ assertSupported("https://www.youtube.com/watch?v=abc&list=PLxyz", "youtube", "playlist");+});++test("YouTube: youtu.be short link", () => {+ assertSupported("https://youtu.be/dQw4w9WgXcQ", "youtube", "video");+});++test("YouTube: shorts", () => {+ assertSupported("https://www.youtube.com/shorts/abc123", "youtube", "short");+});++test("YouTube: playlist page", () => {+ assertSupported("https://www.youtube.com/playlist?list=PLxyz", "youtube", "playlist");+});++test("YouTube: live stream", () => {+ assertSupported("https://www.youtube.com/live/abc123", "youtube", "video");+});++test("YouTube: embed", () => {+ assertSupported("https://www.youtube.com/embed/abc123", "youtube", "video");+});++test("YouTube: old embed /v/ format", () => {+ assertSupported("https://www.youtube.com/v/abc123", "youtube", "video");+});++test("YouTube: channel page is unsupported", () => {+ assertUnsupported("https://www.youtube.com/@omniget", "youtube", "profile");+ assertUnsupported("https://www.youtube.com/channel/UCxyz", "youtube", "profile");+ assertUnsupported("https://www.youtube.com/c/omniget", "youtube", "profile");+});++test("YouTube: youtube-nocookie.com", () => {+ assertSupported("https://www.youtube-nocookie.com/embed/abc123", "youtube", "video");+});++// ── Instagram ────────────────────────────────────────────────────────────++test("Instagram: post", () => {+ assertSupported("https://www.instagram.com/p/CxyzABC/", "instagram", "post");+});++test("Instagram: reel", () => {+ assertSupported("https://www.instagram.com/reel/abc123/", "instagram", "reel");+});++test("Instagram: story", () => {+ assertSupported("https://www.instagram.com/stories/user/12345/", "instagram", "image");+});++test("Instagram: profile is unsupported", () => {+ assertUnsupported("https://www.instagram.com/username", "instagram", "profile");+});++test("Instagram: explore is unknown", () => {+ assertUnsupported("https://www.instagram.com/explore", "instagram", "unknown");+});++test("Instagram: ddinstagram.com mirror", () => {+ assertSupported("https://www.ddinstagram.com/reel/abc123/", "instagram", "reel");+});++// ── TikTok ───────────────────────────────────────────────────────────────++test("TikTok: user video", () => {+ assertSupported("https://www.tiktok.com/@user/video/1234567890", "tiktok", "video");+});++test("TikTok: profile is unsupported", () => {+ assertUnsupported("https://www.tiktok.com/@user", "tiktok", "profile");+});++test("TikTok: explore page is unknown", () => {+ assertUnsupported("https://www.tiktok.com/explore", "tiktok", "unknown");+});++test("TikTok: foryou page is unknown", () => {+ assertUnsupported("https://www.tiktok.com/foryou", "tiktok", "unknown");+});++// ── Twitter / X ──────────────────────────────────────────────────────────++test("Twitter: post/status", () => {+ assertSupported("https://twitter.com/user/status/123456", "twitter", "post");+ assertSupported("https://x.com/user/status/123456", "twitter", "post");+});++test("Twitter: vxtwitter mirror", () => {+ assertSupported("https://vxtwitter.com/user/status/123456", "twitter", "post");+});++test("Twitter: fixvx mirror", () => {+ assertSupported("https://fixvx.com/user/status/123456", "twitter", "post");+});++test("Twitter: profile is unsupported", () => {+ assertUnsupported("https://twitter.com/user", "twitter", "profile");+});++test("Twitter: search/explore/settings are unknown", () => {+ assertUnsupported("https://twitter.com/search", "twitter", "unknown");+ assertUnsupported("https://twitter.com/explore", "twitter", "unknown");+ assertUnsupported("https://twitter.com/settings", "twitter", "unknown");+ assertUnsupported("https://twitter.com/i", "twitter", "unknown");+});++// ── Reddit ───────────────────────────────────────────────────────────────++test("Reddit: subreddit post", () => {+ assertSupported("https://www.reddit.com/r/videos/comments/abc123/example/", "reddit", "post");});-test("flags YouTube channel pages as unsupported", () => {- const detected = detectSupportedMediaUrl("https://www.youtube.com/@omniget");- assert.equal(detected?.platform, "youtube");- assert.equal(detected?.contentType, "profile");- assert.equal(detected?.supported, false);+test("Reddit: short comment link", () => {+ assertSupported("https://www.reddit.com/comments/abc123/", "reddit", "post");});-test("flags Instagram reels as supported", () => {- const detected = detectSupportedMediaUrl("https://www.instagram.com/reel/abc123/");- assert.equal(detected?.contentType, "reel");- assert.equal(detected?.supported, true);+test("Reddit: v.redd.it direct link", () => {+ assertSupported("https://v.redd.it/abc123", "reddit", "video");+});++test("Reddit: redd.it short link", () => {+ assertSupported("https://redd.it/abc123", "reddit", "video");+});++test("Reddit: /r/sub/s/ share link", () => {+ assertSupported("https://www.reddit.com/r/funny/s/abc123/", "reddit", "post");+});++test("Reddit: /video/ link", () => {+ assertSupported("https://www.reddit.com/video/abc123", "reddit", "video");+});++test("Reddit: subreddit browse is unsupported profile", () => {+ assertUnsupported("https://www.reddit.com/r/videos", "reddit", "profile");+});++test("Reddit: homepage is unknown", () => {+ assertUnsupported("https://www.reddit.com/", "reddit", "unknown");+});++test("Reddit: random top-level path is unknown", () => {+ assertUnsupported("https://www.reddit.com/best", "reddit", "unknown");+});++// ── Twitch ───────────────────────────────────────────────────────────────++test("Twitch: VOD video", () => {+ assertSupported("https://www.twitch.tv/videos/123456", "twitch", "video");+});++test("Twitch: clip via clips subdomain", () => {+ assertSupported("https://clips.twitch.tv/FunnyClipName", "twitch", "clip");+});++test("Twitch: clip via /clip/ path", () => {+ assertSupported("https://www.twitch.tv/streamer/clip/ClipName", "twitch", "clip");+});++test("Twitch: live stream channel is supported as video", () => {+ assertSupported("https://www.twitch.tv/shroud", "twitch", "video");+});++test("Twitch: directory page is unknown", () => {+ assertUnsupported("https://www.twitch.tv/directory", "twitch", "unknown");+});++test("Twitch: settings page is unknown", () => {+ assertUnsupported("https://www.twitch.tv/settings", "twitch", "unknown");+});++// ── Hotmart ──────────────────────────────────────────────────────────────++test("Hotmart: course page", () => {+ assertSupported("https://app.hotmart.com/club/abc/lesson/xyz", "hotmart", "course");+});++test("Hotmart: generic page is unknown", () => {+ assertUnsupported("https://app.hotmart.com/dashboard", "hotmart", "unknown");+});++// ── Pinterest ────────────────────────────────────────────────────────────++test("Pinterest: pin page", () => {+ assertSupported("https://www.pinterest.com/pin/123456/", "pinterest", "image");+});++test("Pinterest: pin.it short link", () => {+ const detected = detectSupportedMediaUrl("https://pin.it/abc123");+ assert.equal(detected?.platform, "pinterest");+});++test("Pinterest: country TLD", () => {+ assertSupported("https://www.pinterest.co.uk/pin/123456/", "pinterest", "image");+ assertSupported("https://www.pinterest.fr/pin/123456/", "pinterest", "image");+ assertSupported("https://br.pinterest.com/pin/123456/", "pinterest", "image");+});++test("Pinterest: does not match notpinterest.com", () => {+ assertNull("https://notpinterest.com/pin/123");+});++test("Pinterest: profile page is unknown", () => {+ assertUnsupported("https://www.pinterest.com/username/", "pinterest", "unknown");+});++// ── Bluesky ──────────────────────────────────────────────────────────────++test("Bluesky: post", () => {+ assertSupported("https://bsky.app/profile/user.bsky.social/post/abc123", "bluesky", "post");+});++test("Bluesky: profile is unsupported", () => {+ assertUnsupported("https://bsky.app/profile/user.bsky.social", "bluesky", "profile");+});++// ── Telegram ─────────────────────────────────────────────────────────────++test("Telegram: numbered post", () => {+ assertSupported("https://t.me/channel/123", "telegram", "post");+});++test("Telegram: channel profile is unsupported", () => {+ assertUnsupported("https://t.me/channel", "telegram", "profile");+});++test("Telegram: joinchat is unknown", () => {+ assertUnsupported("https://t.me/joinchat", "telegram", "unknown");+});++test("Telegram: telegram.me domain", () => {+ assertSupported("https://telegram.me/channel/456", "telegram", "post");+});++// ── Vimeo ────────────────────────────────────────────────────────────────++test("Vimeo: numeric video ID", () => {+ assertSupported("https://vimeo.com/123456", "vimeo", "video");+});++test("Vimeo: non-numeric path is unknown", () => {+ assertUnsupported("https://vimeo.com/channels", "vimeo", "unknown");+});++// ── Udemy ────────────────────────────────────────────────────────────────++test("Udemy: course page", () => {+ assertSupported("https://www.udemy.com/course/my-course/", "udemy", "course");+});++test("Udemy: homepage is unknown", () => {+ assertUnsupported("https://www.udemy.com/", "udemy", "unknown");+});++// ── Bilibili ─────────────────────────────────────────────────────────────++test("Bilibili: video page", () => {+ assertSupported("https://www.bilibili.com/video/BV1xx411c7XY", "bilibili", "video");});-test("flags Reddit post pages as supported", () => {- const detected = detectSupportedMediaUrl("https://www.reddit.com/r/videos/comments/abc123/example/");- assert.equal(detected?.contentType, "post");- assert.equal(detected?.supported, true);+test("Bilibili: b23.tv short link", () => {+ const detected = detectSupportedMediaUrl("https://b23.tv/abc123");+ assert.equal(detected?.platform, "bilibili");});-test("keeps generic pages unsupported", () => {- assert.equal(detectSupportedMediaUrl("https://www.google.com/search?q=omniget"), null);+test("Bilibili: homepage is unknown", () => {+ assertUnsupported("https://www.bilibili.com/", "bilibili", "unknown");});diff --git a/src-tauri/src/native_host.rs b/src-tauri/src/native_host.rsindex 3ee1135c..14a8deb2 100644--- a/src-tauri/src/native_host.rs+++ b/src-tauri/src/native_host.rs@@ -58,7 +58,7 @@ pub fn ensure_registered() -> anyhow::Result<()> {fs::create_dir_all(&integration_dir)?;let host_exe = integration_dir.join(HOST_COPY_NAME);- if current_exe != host_exe {+ if current_exe != host_exe && should_copy_exe(¤t_exe, &host_exe) {fs::copy(¤t_exe, &host_exe)?;}@@ -106,11 +106,24 @@ pub fn ensure_registered() -> anyhow::Result<()> {Ok(())}+// TODO: implement native messaging host registration for macOS+// (~/.config/google-chrome/NativeMessagingHosts/ on Linux,+// ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/ on macOS)#[cfg(not(target_os = "windows"))]pub fn ensure_registered() -> anyhow::Result<()> {Ok(())}+fn should_copy_exe(source: &Path, dest: &Path) -> bool {+ let Ok(src_meta) = fs::metadata(source) else {+ return true;+ };+ let Ok(dst_meta) = fs::metadata(dest) else {+ return true;+ };+ src_meta.len() != dst_meta.len()+}+fn handle_request(request: NativeHostRequest) -> NativeHostResponse {if request.kind != "enqueue" {return NativeHostResponse {@@ -165,10 +178,18 @@ fn launch_omniget(url: &str) -> anyhow::Result<()> {}fn read_message() -> anyhow::Result<NativeHostRequest> {+ const MAX_MESSAGE_LENGTH: usize = 1_048_576; // 1 MB — Chrome's own limit+let mut length_bytes = [0u8; 4];std::io::stdin().read_exact(&mut length_bytes)?;let length = u32::from_le_bytes(length_bytes) as usize;+ if length > MAX_MESSAGE_LENGTH {+ anyhow::bail!(+ "Native message too large ({length} bytes, max {MAX_MESSAGE_LENGTH})"+ );+ }+let mut payload = vec![0u8; length];std::io::stdin().read_exact(&mut payload)?;Ok(serde_json::from_slice(&payload)?)