diff --git a/RELEASING.md b/RELEASING.md index d15806b04..ce810318e 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -170,9 +170,45 @@ The script takes a plain `X.Y.Z`; for a prerelease version such as Do not rerun an asset workflow after publication without first returning the release to draft. The workflows also write the channel updater manifests (`latest-{target}-{arch}.json` and - `latest-{target}-{arch}-beta.json`) but deliberately keep them **out** of the release assets — - current clients read the CDN, not the release. Download them from the run and publish them to - the CDN as part of publishing the release: + `latest-{target}-{arch}-beta.json`) but deliberately keep them **out** of the release assets. + Current clients read those manifests from Aliyun, not from the GitHub Release. Download the + manifest artifacts from the run. Uploading them is only half of the Aliyun step: the binary + packages named by those manifests must be uploaded to Aliyun as well. See + [Aliyun artifacts](#aliyun-artifacts) below. Clients built before the CDN switch read the old + `releases/latest/download/latest-*.json` assets, which new releases no longer carry, so they + need one manual download. +7. Publishing Stable with the administrator's CLI/UI credential automatically + triggers `sync-homebrew-cask.yml`. It accepts only the published latest Stable + tag, preserves application build metadata in DMG filenames, verifies matching + ARM/Intel versions, computes their checksums and commits the cask update. + Drafts, Beta and older releases never update Homebrew. If repair is needed, run + `gh workflow run sync-homebrew-cask.yml -f tag=v-tauri`; no asset rebuild + or manual cask edit is needed. Do not publish via an asset workflow's + `GITHUB_TOKEN`, which does not emit the downstream release event. + +## Aliyun artifacts + +阿里云这里要上传二进制产物。客户端先向阿里云要文件;阿里云能拉到就从阿里云下载,因为这条链路更快;阿里云没有拉到就改从 GitHub 下载同一份产物。 + +Aliyun here is `https://dl.aeoform.com` (ESA). A published GitHub Release does not put anything +on Aliyun. After the tag workflows succeed, upload both of the following. + +1. **Binary artifacts.** Upload every updater package the manifest will name, byte-for-byte the + same object as the GitHub Release asset: + + ```text + https://dl.aeoform.com/releases/{tag}/{asset} + ``` + + This includes the macOS `OpenLess_{arch}.app.tar.gz` archives, the Windows + `*-setup.exe`, and the Android APKs. Website alias installers (`OpenLess_macos_aarch64.dmg` + and the other short names) belong at the same prefix when those URLs are handed out. + `.sig` files are not a separate client download; the signature stays inside the manifest. + Do not stop after uploading the JSON. An Aliyun manifest that points at a missing object + makes the download 404. + +2. **Rolling manifests.** Download these from the workflow artifacts and overwrite them in + place. The file name is per platform and channel, never per version. | platform | workflow artifact | | --- | --- | @@ -180,27 +216,29 @@ The script takes a plain `X.Y.Z`; for a prerelease version such as | Windows | `openless-windows-x64-updater` | | Android | `openless-android-updater-manifests` | - Destination (overwrite in place; the file name is per platform and channel, never per - version): - ```text https://dl.aeoform.com/updates/stable/latest-{target}-{arch}.json https://dl.aeoform.com/updates/beta/latest-{target}-{arch}-beta.json ``` - Their `url` fields must point at the CDN artifacts (`.../releases/{tag}/{asset}`). - Manifest upload is the step that makes a release reachable by auto-update: a published - release whose manifests were not synced is downloadable by hand but invisible to the updater. - Clients built before the CDN switch read the old `releases/latest/download/latest-*.json` - assets, which new releases no longer carry, so they need one manual download. -7. Publishing Stable with the administrator's CLI/UI credential automatically - triggers `sync-homebrew-cask.yml`. It accepts only the published latest Stable - tag, preserves application build metadata in DMG filenames, verifies matching - ARM/Intel versions, computes their checksums and commits the cask update. - Drafts, Beta and older releases never update Homebrew. If repair is needed, run - `gh workflow run sync-homebrew-cask.yml -f tag=v-tauri`; no asset rebuild - or manual cask edit is needed. Do not publish via an asset workflow's - `GITHUB_TOKEN`, which does not emit the downstream release event. + The manifest `url` must stay the Aliyun object (`.../releases/{tag}/{asset}`). Do not write + the GitHub URL into the manifest. There is no GitHub copy of this JSON. If the previous + JSON is still what clients receive after the overwrite, purge that JSON path on Aliyun. + +**Client order.** Builds that contain the fallback ask Aliyun for the binary first. When Aliyun +returns the object, the download stays on Aliyun because that path is faster. When Aliyun does +not serve it (the object is missing, the response is not successful, or the request fails), the +client downloads the same `{tag}/{asset}` from: + +```text +https://github.com/Open-Less/openless/releases/download/{tag}/{asset} +``` + +The minisign signature still has to match those bytes. Clients installed before this fallback +only know the Aliyun URL. For those installs, both the rolling JSON and the binary have to be +on Aliyun. A JSON file that still names the previous version makes the in-app check report +"already current" and never starts a download. Uploading the binaries alone does not change +that. Before dispatching the Linux release build, additionally require all of the following: diff --git a/openless-all/app/src-tauri/src/android/updater.rs b/openless-all/app/src-tauri/src/android/updater.rs index eea55ba01..5752985dd 100644 --- a/openless-all/app/src-tauri/src/android/updater.rs +++ b/openless-all/app/src-tauri/src/android/updater.rs @@ -78,8 +78,9 @@ mod android_impl { pub async fn check_update(channel: UpdateChannel) -> Result, String> { let arch = device_arch()?; - // Manifests live on the project CDN; channel is a URL path, not a filename suffix, so - // there is no tag discovery and no GitHub dependency (see `crate::update_source`). + // The rolling manifest stays on Aliyun. Channel is a URL path, not a filename suffix. + // Binary fallback to GitHub happens in the download command, after this check returns + // the manifest `url` (see `crate::update_source`). let url = crate::update_source::manifest_url(channel, "android", arch); let current = env!("CARGO_PKG_VERSION").to_string(); match fetch_manifest(&url).await { diff --git a/openless-all/app/src-tauri/src/commands/settings.rs b/openless-all/app/src-tauri/src/commands/settings.rs index bf1991cdc..084072f08 100644 --- a/openless-all/app/src-tauri/src/commands/settings.rs +++ b/openless-all/app/src-tauri/src/commands/settings.rs @@ -738,11 +738,12 @@ fn extract_between(haystack: &str, open: &str, close: &str) -> Option { // - Beta channel: swap in `https://dl.aeoform.com/updates/beta/...-beta.json` through // builder.endpoints(vec![url])?.build()?.check(). // -// Manifests live on the project CDN instead of the GitHub Release assets (see -// `crate::update_source`), so a release no longer accumulates fourteen `latest-*.json` copies. -// The channel split is now a URL *path* (`/updates/stable/` vs `/updates/beta/`) instead of a -// filename suffix, and artifact URLs inside the manifest point at the same CDN — a Stable -// client can never reach a Beta package, and mainland-China downloads never touch github.com. +// Manifests live on Aliyun instead of the GitHub Release assets (see `crate::update_source`), +// so a release no longer accumulates fourteen `latest-*.json` copies. The channel split is a +// URL path (`/updates/stable/` vs `/updates/beta/`). The manifest `url` names the Aliyun +// object at `/releases/{tag}/{asset}`. Before this check hands the plugin an `Update`, it +// probes that object: Aliyun is used when the probe succeeds, and the same asset is taken +// from GitHub when Aliyun does not serve it. A Stable manifest still cannot name a Beta path. // // The returned Metadata shape exactly matches plugin-updater's JS UpdateMetadata (rid + // currentVersion and other camelCase fields), so the frontend can call @@ -796,9 +797,20 @@ pub async fn app_check_update_with_channel( .await .map_err(|e| format!("check update failed: {e}"))?; - let Some(update) = update else { + let Some(mut update) = update else { return Ok(None); }; + // The plugin downloads `Update.download_url` and ignores a later change to the JS copy. + // Choose Aliyun or GitHub before the resource is stored. + let chosen = + crate::update_source::resolve_artifact_download_url(update.download_url.as_str()).await; + if chosen != update.download_url.as_str() { + update.download_url = + url::Url::parse(&chosen).map_err(|e| format!("parse artifact fallback url: {e}"))?; + if let Some(object) = update.raw_json.as_object_mut() { + object.insert("url".to_string(), serde_json::Value::String(chosen)); + } + } // Passing through the date field would require the time crate; the frontend // AutoUpdate.tsx never uses date, so set it to None here and avoid pulling a new dep // into src-tauri/Cargo.toml. @@ -816,8 +828,8 @@ pub async fn app_check_update_with_channel( /// The Beta manifest endpoint, with `{{target}}` / `{{arch}}` left in place for /// `tauri-plugin-updater` to substitute at check time. /// -/// Beta is a URL *path* on the CDN (`/updates/beta/`), so there is no tag discovery step and -/// no dependency on `releases.atom` or the GitHub Release assets. +/// Beta is a URL path on Aliyun (`/updates/beta/`). Tag discovery is not required. The +/// manifest JSON is not read from GitHub; only a missing Aliyun binary falls back there. #[cfg(not(mobile))] fn beta_manifest_endpoint() -> Result { let template = crate::update_source::endpoint_template(UpdateChannel::Beta); @@ -875,8 +887,9 @@ pub async fn app_download_and_install_android_update( signature: String, version: String, ) -> Result<(), String> { - // Parse and validate the host before downloading so userinfo and hostname-prefix tricks - // cannot turn the signed update fetch into an SSRF primitive. + // Prefer the Aliyun object. When that probe does not succeed, use the GitHub asset of + // the same tag and name, then reject anything outside the release-host allowlist. + let url = crate::update_source::resolve_artifact_download_url(&url).await; if !is_allowed_android_update_url(&url) { return Err(format!("不信任的更新 URL,拒绝下载: {url}")); } diff --git a/openless-all/app/src-tauri/src/update_source.rs b/openless-all/app/src-tauri/src/update_source.rs index 26ca3f528..ce0d85acb 100644 --- a/openless-all/app/src-tauri/src/update_source.rs +++ b/openless-all/app/src-tauri/src/update_source.rs @@ -26,14 +26,35 @@ //! //! The manifest body is unchanged (`version`, `pub_date`, `url`, `signature`), so //! `tauri-plugin-updater` keeps owning download, minisign verification and platform install. -//! Artifact URLs inside the manifest point at the same CDN (`/releases/{tag}/{asset}`), which -//! is what mainland-China users download from. +//! +//! # Aliyun artifacts, then GitHub +//! +//! Maintainers upload the binary artifacts to Aliyun at +//! `https://dl.aeoform.com/releases/{tag}/{asset}`. The manifest `url` always names that +//! Aliyun object. At download time the client asks Aliyun first: a successful fetch stays +//! on Aliyun because that path is faster. When Aliyun does not serve the object (missing, +//! non-success, or the probe fails), the same `{tag}/{asset}` is downloaded from +//! `https://github.com/Open-Less/openless/releases/download/{tag}/{asset}`. +//! The rolling JSON itself has no GitHub copy. A client can only discover a new version +//! after that JSON is overwritten on Aliyun. + +use std::time::Duration; use crate::types::UpdateChannel; /// CDN that serves both the update manifests and the mirrored release artifacts. pub(crate) const CDN_BASE: &str = "https://dl.aeoform.com"; +/// Host that must appear on an Aliyun artifact URL before it can fall back to GitHub. +const CDN_HOST: &str = "dl.aeoform.com"; + +/// GitHub Release download prefix for the same `{tag}/{asset}` Aliyun stores. +const GITHUB_RELEASE_DOWNLOAD_BASE: &str = + "https://github.com/Open-Less/openless/releases/download"; + +/// How long the Aliyun existence probe may wait before the download uses GitHub. +const ARTIFACT_PROBE_TIMEOUT: Duration = Duration::from_secs(8); + /// Manifest URL for `channel`, with the `{{target}}` / `{{arch}}` tokens left in place for /// `tauri-plugin-updater` to substitute at check time. /// @@ -58,6 +79,162 @@ pub fn manifest_url(channel: UpdateChannel, target: &str, arch: &str) -> String .replace("{{arch}}", arch) } +/// Map one Aliyun release object to the GitHub Release asset of the same name. +/// +/// Accepts only `https://dl.aeoform.com/releases/{tag}/{asset}` with a single tag segment +/// and a single asset segment. Any other host, scheme, userinfo, port, query, extra slash, +/// or `..` segment returns `None` so a manifest cannot redirect the download elsewhere. +pub fn github_fallback_for_cdn_artifact(raw: &str) -> Option { + let parsed = url::Url::parse(raw).ok()?; + if parsed.scheme() != "https" + || parsed.host_str() != Some(CDN_HOST) + || !parsed.username().is_empty() + || parsed.password().is_some() + || parsed.port().is_some() + || parsed.query().is_some() + || parsed.fragment().is_some() + { + return None; + } + + let mut segments = parsed.path_segments()?; + if segments.next()? != "releases" { + return None; + } + // `path_segments` keeps percent-encoding. Decode once so `%2B` is the same asset as `+`, + // then reject a decoded slash or `..` before encoding the GitHub path. + let tag = decode_path_segment(segments.next()?)?; + let asset = decode_path_segment(segments.next()?)?; + if segments.next().is_some() || !is_single_path_segment(&tag) || !is_single_path_segment(&asset) + { + return None; + } + + Some(format!( + "{GITHUB_RELEASE_DOWNLOAD_BASE}/{}/{}", + encode_path_segment(&tag), + encode_path_segment(&asset) + )) +} + +/// Keep `cdn_url` when Aliyun served the object. Otherwise use the GitHub asset URL when +/// the input is an Aliyun release object, and leave every other URL unchanged. +pub fn select_artifact_url(cdn_url: &str, cdn_available: bool) -> String { + if cdn_available { + return cdn_url.to_string(); + } + github_fallback_for_cdn_artifact(cdn_url).unwrap_or_else(|| cdn_url.to_string()) +} + +/// Probe the Aliyun object and return the URL the downloader should GET. +/// +/// A non-Aliyun URL is returned unchanged. Aliyun wins on HTTP 2xx. HEAD 403/405 is confirmed +/// with a one-byte range so a CDN that refuses HEAD can still be used. 404, any other +/// non-success, and a network or timeout failure all count as "Aliyun did not serve the +/// file" and select GitHub. The probe never reads the artifact body. +pub async fn resolve_artifact_download_url(url: &str) -> String { + if github_fallback_for_cdn_artifact(url).is_none() { + return url.to_string(); + } + let available = aliyun_artifact_reachable(url).await; + let chosen = select_artifact_url(url, available); + if !available { + log::info!("[updater] Aliyun artifact was not fetched; downloading from GitHub"); + } + chosen +} + +fn decode_path_segment(segment: &str) -> Option { + let bytes = segment.as_bytes(); + let mut decoded = Vec::with_capacity(bytes.len()); + let mut index = 0; + while index < bytes.len() { + if bytes[index] == b'%' { + if index + 2 >= bytes.len() { + return None; + } + let hex = std::str::from_utf8(&bytes[index + 1..index + 3]).ok()?; + let value = u8::from_str_radix(hex, 16).ok()?; + decoded.push(value); + index += 3; + continue; + } + decoded.push(bytes[index]); + index += 1; + } + String::from_utf8(decoded).ok() +} + +fn is_single_path_segment(segment: &str) -> bool { + !segment.is_empty() + && segment != "." + && segment != ".." + && !segment.contains("..") + && !segment.contains(['/', '\\', '\0']) +} + +fn encode_path_segment(segment: &str) -> String { + let mut encoded = String::with_capacity(segment.len()); + for byte in segment.bytes() { + match byte { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + encoded.push(byte as char); + } + _ => encoded.push_str(&format!("%{byte:02X}")), + } + } + encoded +} + +async fn aliyun_artifact_reachable(url: &str) -> bool { + let client = crate::net::http(); + match client + .head(url) + .timeout(ARTIFACT_PROBE_TIMEOUT) + .send() + .await + { + Ok(response) => { + let status = response.status(); + // Drop without reading. A follow-up range probe must not buffer the package. + drop(response); + if status.is_success() { + return true; + } + if status == reqwest::StatusCode::METHOD_NOT_ALLOWED + || status == reqwest::StatusCode::FORBIDDEN + { + return aliyun_range_probe_ok(&client, url).await; + } + false + } + Err(error) => { + log::info!( + "[updater] Aliyun artifact probe failed ({})", + crate::net::request_error_kind(&error) + ); + false + } + } +} + +async fn aliyun_range_probe_ok(client: &reqwest::Client, url: &str) -> bool { + match client + .get(url) + .header(reqwest::header::RANGE, "bytes=0-0") + .timeout(ARTIFACT_PROBE_TIMEOUT) + .send() + .await + { + Ok(response) => { + let status = response.status(); + drop(response); + status == reqwest::StatusCode::OK || status == reqwest::StatusCode::PARTIAL_CONTENT + } + Err(_) => false, + } +} + #[cfg(test)] mod tests { use super::*; @@ -127,4 +304,64 @@ mod tests { assert!(!CDN_BASE.ends_with('/')); assert!(endpoint_template(UpdateChannel::Stable).starts_with(CDN_BASE)); } + + #[test] + fn aliyun_artifact_maps_to_the_github_release_asset() { + let cdn = "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess_aarch64.app.tar.gz"; + assert_eq!( + github_fallback_for_cdn_artifact(cdn).as_deref(), + Some( + "https://github.com/Open-Less/openless/releases/download/v2.0.2-Beta.4-tauri/OpenLess_aarch64.app.tar.gz" + ) + ); + } + + #[test] + fn percent_encoded_plus_stays_a_single_github_asset_segment() { + let encoded = "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess_2.0.2-Beta.4%2Bbuild.20261106-16d927ba_x64-setup.exe"; + let literal_plus = "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess_2.0.2-Beta.4+build.20261106-16d927ba_x64-setup.exe"; + let expected = "https://github.com/Open-Less/openless/releases/download/v2.0.2-Beta.4-tauri/OpenLess_2.0.2-Beta.4%2Bbuild.20261106-16d927ba_x64-setup.exe"; + assert_eq!( + github_fallback_for_cdn_artifact(encoded).as_deref(), + Some(expected) + ); + assert_eq!( + github_fallback_for_cdn_artifact(literal_plus).as_deref(), + Some(expected) + ); + } + + #[test] + fn github_fallback_rejects_anything_except_one_aliyun_release_object() { + for rejected in [ + "https://github.com/Open-Less/openless/releases/download/v2.0.2-Beta.4-tauri/OpenLess.dmg", + "https://dl.aeoform.com/updates/beta/latest-darwin-aarch64-beta.json", + "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/dir/OpenLess.dmg", + "https://dl.aeoform.com/releases/../OpenLess.dmg", + "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/../OpenLess.dmg", + "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess%2Fevil.dmg", + "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess%.dmg", + "http://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess.dmg", + "https://dl.aeoform.com.evil.example/releases/v2.0.2-Beta.4-tauri/OpenLess.dmg", + "https://user:pass@dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess.dmg", + "https://dl.aeoform.com:8443/releases/v2.0.2-Beta.4-tauri/OpenLess.dmg", + "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess.dmg?redirect=1", + ] { + assert_eq!( + github_fallback_for_cdn_artifact(rejected), + None, + "{rejected}" + ); + } + } + + #[test] + fn select_artifact_url_prefers_aliyun_and_falls_back_only_when_missing() { + let cdn = "https://dl.aeoform.com/releases/v2.0.2-Beta.4-tauri/OpenLess_aarch64.app.tar.gz"; + let github = github_fallback_for_cdn_artifact(cdn).expect("cdn url"); + assert_eq!(select_artifact_url(cdn, true), cdn); + assert_eq!(select_artifact_url(cdn, false), github); + let already_github = github.as_str(); + assert_eq!(select_artifact_url(already_github, false), already_github); + } }