From f5b4103181194609226f9ff41b6a5aef5a7cda94 Mon Sep 17 00:00:00 2001 From: Diogo Matias <1090355+sathran@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:38:50 +0000 Subject: [PATCH 1/7] Fetch catalogue icons and README images only from the listed hosts The allowlist took the host by splitting on '/', so https://evil.example?.wago.io/a.png passed. It now parses the URL. Catalogue icons had no host limit at all, and the catalogue is read live at launch, so they now use the same list, in the app and in the validator. --- CONTRIBUTING.md | 1 + scripts/validate-catalog.js | 13 +++++++++++++ src-tauri/src/catalog.rs | 1 + src-tauri/src/icons.rs | 35 +++++++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 154b0f5..074eac2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,7 @@ An entry looks like this: | `desc`, `category`, `url` | no | shown in Browse | | `notice` | no | one short line (160 chars) shown in amber on the installed row. For "remove this once X is fixed" situations. | | `added` | no | `YYYY-MM-DD` the entry was added. Kept for the record and for sorting later. | +| `icon` | no | https image for Browse, on GitHub, `media.forgecdn.net`, Wago or WoWInterface. Other hosts are refused. Leave it out to use the GitHub avatar. | Set `group_required_dependencies: true` only when the download bundles the first folder's required dependencies, as Questie does with QuestieDB. Keep those diff --git a/scripts/validate-catalog.js b/scripts/validate-catalog.js index 43a751c..3c87073 100644 --- a/scripts/validate-catalog.js +++ b/scripts/validate-catalog.js @@ -24,6 +24,18 @@ const folderOwner = new Map(); const idRe = /^[a-z0-9]+(-[a-z0-9]+)*$/; const repoRe = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/; const dateRe = /^\d{4}-\d{2}-\d{2}$/; +// Same hosts as allowed_image_host in src-tauri/src/icons.rs. +function allowedImageHost(value) { + try { + const url = new URL(value); + if (url.protocol !== "https:" || url.username || url.password) return false; + const host = url.hostname; + return host === "github.com" || host.endsWith(".githubusercontent.com") || host === "media.forgecdn.net" + || host === "addons.wago.io" || host.endsWith(".wago.io") || host === "www.wowinterface.com" || host === "cdn-wow.mmoui.com"; + } catch { + return false; + } +} const knownKeys = new Set(["id", "name", "desc", "category", "github", "wago", "wowi", "tukui", "curse", "asset_hint", "folders", "group_required_dependencies", "curse_locked", "url", "forever", "icon", "notice", "added", "github_moved_from"]); for (const [i, a] of (cat.addons || []).entries()) { @@ -51,6 +63,7 @@ for (const [i, a] of (cat.addons || []).entries()) { if (a.tukui !== undefined && typeof a.tukui !== "string") problems.push(`${where}: "tukui" must be a slug`); if (a.asset_hint !== undefined && typeof a.asset_hint !== "string") problems.push(`${where}: "asset_hint" must be a string`); if (a.url !== undefined && !/^https?:\/\//.test(a.url)) problems.push(`${where}: "url" must start with http(s)://`); + if (a.icon !== undefined && (typeof a.icon !== "string" || !allowedImageHost(a.icon))) problems.push(`${where}: "icon" must be an https URL on GitHub, CurseForge's media host, Wago or WoWInterface`); if (a.notice !== undefined && (typeof a.notice !== "string" || a.notice.length > 160)) problems.push(`${where}: "notice" must be a short string (160 chars max)`); if (a.added !== undefined && !dateRe.test(a.added)) problems.push(`${where}: "added" must be YYYY-MM-DD`); if (a.forever !== undefined && a.forever !== null && typeof a.forever !== "boolean") problems.push(`${where}: "forever" must be true, false or null`); diff --git a/src-tauri/src/catalog.rs b/src-tauri/src/catalog.rs index ec77489..17c4a0d 100644 --- a/src-tauri/src/catalog.rs +++ b/src-tauri/src/catalog.rs @@ -53,6 +53,7 @@ pub struct CatalogEntry { #[serde(default)] pub forever: Option, /// Optional https icon for the Browse list (else the GitHub avatar is used). + /// Only fetched from the hosts in `icons::allowed_image_host`. #[serde(default)] pub icon: Option, /// A short line shown on the installed row, e.g. "beta workaround, remove diff --git a/src-tauri/src/icons.rs b/src-tauri/src/icons.rs index fa4cc40..4c724d7 100644 --- a/src-tauri/src/icons.rs +++ b/src-tauri/src/icons.rs @@ -98,7 +98,8 @@ pub fn local_icon(install: &Path, texture: &str) -> Option { /// Fetch an https image (GitHub avatar or a catalogue `icon` URL), cached for 30 days. pub async fn remote_icon(client: &reqwest::Client, url: &str) -> Option { - if !url.starts_with("https://") { + // The catalogue is fetched live, so its `icon` field gets the same limit as README images. + if !allowed_image_host(url) { return None; } let cache = cache_dir().join(format!("{}.png", key(url))); @@ -142,11 +143,13 @@ const README_TTL: Duration = Duration::from_secs(24 * 3600); /// Hosts an image may come from for the preview. The app promises to talk /// only to the addon sites, so anything else in a README is ignored. fn allowed_image_host(url: &str) -> bool { - let rest = match url.strip_prefix("https://") { - Some(r) => r, - None => return false, - }; - let host = rest.split('/').next().unwrap_or("").to_ascii_lowercase(); + // A real URL parse: `https://evil.example?.wago.io/a.png` has the host evil.example. + let Ok(parsed) = reqwest::Url::parse(url) else { return false }; + if parsed.scheme() != "https" || !parsed.username().is_empty() || parsed.password().is_some() { + return false; + } + let Some(host) = parsed.host_str() else { return false }; + let host = host.to_ascii_lowercase(); host == "github.com" || host.ends_with(".githubusercontent.com") || host == "media.forgecdn.net" @@ -544,6 +547,26 @@ pub async fn preview_image(client: &reqwest::Client, url: &str) -> Option Date: Tue, 3 Nov 2026 22:39:05 +0000 Subject: [PATCH 2/7] Require HTTPS on every request and keep the CurseForge key on its host Download URLs from the WoWInterface and TukUI APIs were used as returned, and redirects could downgrade to http. Every URL those APIs return for the catalogue is https today, so nothing should break. reqwest keeps custom headers on cross-host redirects, so x-api-key would follow a redirect off api.curseforge.com. That redirect is now an error. --- src-tauri/src/lib.rs | 13 +++++++++++++ src-tauri/src/sources/curseforge.rs | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7857384..241baa0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1639,8 +1639,21 @@ fn redact_paths(text: &str) -> String { // ---------------------------------------------------------------- boot fn make_app() -> Shared { + let redirects = reqwest::redirect::Policy::custom(|attempt| { + let from = attempt.previous().last().and_then(|u| u.host_str().map(str::to_owned)); + if attempt.previous().len() >= 10 { + attempt.error("too many redirects") + } else if !sources::curseforge::redirect_keeps_key_home(from.as_deref(), attempt.url().host_str()) { + attempt.error("CurseForge redirected away from its API host") + } else { + attempt.follow() + } + }); let client = reqwest::Client::builder() .user_agent(USER_AGENT) + // Applies to every hop, so a redirect can't downgrade a download to plain http. + .https_only(true) + .redirect(redirects) .timeout(std::time::Duration::from_secs(120)) .connect_timeout(std::time::Duration::from_secs(15)) .build() diff --git a/src-tauri/src/sources/curseforge.rs b/src-tauri/src/sources/curseforge.rs index c108e1b..2c84450 100644 --- a/src-tauri/src/sources/curseforge.rs +++ b/src-tauri/src/sources/curseforge.rs @@ -215,6 +215,13 @@ fn request(client: &reqwest::Client, method: reqwest::Method, url: String) -> an .timeout(Duration::from_secs(20))) } +/// reqwest strips Authorization on a cross-host redirect, but keeps custom headers +/// like `x-api-key`. A redirect leaving the API host could carry the key with it. +pub fn redirect_keeps_key_home(from_host: Option<&str>, to_host: Option<&str>) -> bool { + const API_HOST: &str = "api.curseforge.com"; + from_host != Some(API_HOST) || to_host == Some(API_HOST) +} + fn api_error(status: u16) -> Option { match status { 401 | 403 => Some(anyhow::anyhow!("CurseForge rejected the API key")), @@ -397,6 +404,15 @@ pub async fn resolve(client: &reqwest::Client, id: u64, prerelease: bool) -> any mod tests { use super::*; + #[test] + fn the_key_never_follows_a_redirect_off_the_api_host() { + let api = Some("api.curseforge.com"); + assert!(redirect_keeps_key_home(api, api)); + assert!(!redirect_keeps_key_home(api, Some("evil.example"))); + assert!(!redirect_keeps_key_home(api, None)); + assert!(redirect_keeps_key_home(Some("github.com"), Some("objects.githubusercontent.com"))); + } + fn file(id: u64, name: &str, kind: u8, types: &[u64], url: Option<&str>, date: &str) -> FileInfo { FileInfo { id, From d63a3d99aac806c141a5d2d64004108f07ceee20 Mon Sep 17 00:00:00 2001 From: Diogo Matias <1090355+sathran@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:40:12 +0000 Subject: [PATCH 3/7] Treat imported addon lists as untrusted The install plan put a list's source id into innerHTML unescaped. Sources from a list now pass the same checks as a typed repo, and a list can't install a different repo under a catalogue addon's key. --- scripts/test-ui.js | 3 +++ src-tauri/src/lib.rs | 36 +++++++++++++++++++++++---------- src-tauri/src/sources/mod.rs | 39 +++++++++++++++++++++++++++++++++++- ui/app.js | 2 +- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/scripts/test-ui.js b/scripts/test-ui.js index 0387da3..3f4430b 100644 --- a/scripts/test-ui.js +++ b/scripts/test-ui.js @@ -166,6 +166,9 @@ assert.equal(run("installSources(catalog[3]).length"), 0, 'Wago-only is link onl assert.match(element('browse-list').innerHTML, /