Skip to content

Commit c077f44

Browse files
committed
feat: force endpoint URL to use https on release [TRI-015] (#41)
1 parent d95cc83 commit c077f44

8 files changed

Lines changed: 125 additions & 9 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-utils": patch
4+
---
5+
6+
Force updater endpoint URL to use `https` on release builds.

core/tauri-utils/src/config.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,38 @@ impl TauriConfig {
13591359
}
13601360
}
13611361

1362+
/// A URL to an updater server.
1363+
///
1364+
/// The URL must use the `https` scheme on production.
1365+
#[skip_serializing_none]
1366+
#[derive(Debug, PartialEq, Clone, Serialize)]
1367+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
1368+
pub struct UpdaterEndpoint(pub Url);
1369+
1370+
impl std::fmt::Display for UpdaterEndpoint {
1371+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1372+
write!(f, "{}", self.0)
1373+
}
1374+
}
1375+
1376+
impl<'de> Deserialize<'de> for UpdaterEndpoint {
1377+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1378+
where
1379+
D: Deserializer<'de>,
1380+
{
1381+
let url = Url::deserialize(deserializer)?;
1382+
#[cfg(all(not(debug_assertions), not(feature = "schema")))]
1383+
{
1384+
if url.scheme() != "https" {
1385+
return Err(serde::de::Error::custom(
1386+
"The configured updater endpoint must use the `https` protocol.",
1387+
));
1388+
}
1389+
}
1390+
Ok(Self(url))
1391+
}
1392+
}
1393+
13621394
/// The Updater configuration object.
13631395
#[skip_serializing_none]
13641396
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
@@ -1371,8 +1403,8 @@ pub struct UpdaterConfig {
13711403
/// Display built-in dialog or use event system if disabled.
13721404
#[serde(default = "default_dialog")]
13731405
pub dialog: bool,
1374-
/// The updater endpoints.
1375-
pub endpoints: Option<Vec<String>>,
1406+
/// The updater endpoints. TLS is enforced on production.
1407+
pub endpoints: Option<Vec<UpdaterEndpoint>>,
13761408
/// Signature public key.
13771409
pub pubkey: String,
13781410
}
@@ -2029,7 +2061,18 @@ mod build {
20292061
let active = self.active;
20302062
let dialog = self.dialog;
20312063
let pubkey = str_lit(&self.pubkey);
2032-
let endpoints = opt_vec_str_lit(self.endpoints.as_ref());
2064+
let endpoints = opt_lit(
2065+
self
2066+
.endpoints
2067+
.as_ref()
2068+
.map(|list| {
2069+
vec_lit(list, |url| {
2070+
let url = url.0.as_str();
2071+
quote! { ::tauri::utils::config::UpdaterEndpoint(#url.parse().unwrap()) }
2072+
})
2073+
})
2074+
.as_ref(),
2075+
);
20332076

20342077
literal_struct!(tokens, UpdaterConfig, active, dialog, pubkey, endpoints);
20352078
}

core/tauri/src/updater/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
381381
window: Window<R>,
382382
) {
383383
if let Some(endpoints) = updater_config.endpoints.clone() {
384+
let endpoints = endpoints
385+
.iter()
386+
.map(|e| e.to_string())
387+
.collect::<Vec<String>>();
384388
let env = window.state::<Env>().inner().clone();
385389
// check updates
386390
match self::core::builder(env)
@@ -440,7 +444,9 @@ pub(crate) fn listener<R: Runtime>(
440444
.endpoints
441445
.as_ref()
442446
.expect("Something wrong with endpoints")
443-
.clone();
447+
.iter()
448+
.map(|e| e.to_string())
449+
.collect::<Vec<String>>();
444450

445451
let pubkey = updater_config.pubkey.clone();
446452

examples/updater/src-tauri/Cargo.lock

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/updater/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version = "1.56"
77
license = "Apache-2.0 OR MIT"
88

99
[build-dependencies]
10-
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ] }
10+
tauri-build = { path = "../../../core/tauri-build", features = ["codegen"] }
1111

1212
[dependencies]
1313
serde_json = "1.0"

tooling/cli.rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ notify = "4.0"
3030
shared_child = "1.0"
3131
toml_edit = "0.12"
3232
json-patch = "0.2"
33-
tauri-utils = { version = "1.0.0-beta.3", path = "../../core/tauri-utils" }
33+
tauri-utils = { version = "1.0.0-beta.3", path = "../../core/tauri-utils", features = ["isolation", "schema"] }
3434
schemars = { version = "0.8", features = ["url"] }
3535
toml = "0.5"
3636
valico = "3.6"

tooling/cli.rs/schema.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,13 +1551,13 @@
15511551
"type": "boolean"
15521552
},
15531553
"endpoints": {
1554-
"description": "The updater endpoints.",
1554+
"description": "The updater endpoints. TLS is enforced on production.",
15551555
"type": [
15561556
"array",
15571557
"null"
15581558
],
15591559
"items": {
1560-
"type": "string"
1560+
"$ref": "#/definitions/UpdaterEndpoint"
15611561
}
15621562
},
15631563
"pubkey": {
@@ -1567,6 +1567,11 @@
15671567
},
15681568
"additionalProperties": false
15691569
},
1570+
"UpdaterEndpoint": {
1571+
"description": "A URL to an updater server.\n\nThe URL must use the `https` scheme on production.",
1572+
"type": "string",
1573+
"format": "uri"
1574+
},
15701575
"WindowAllowlistConfig": {
15711576
"description": "Allowlist for the window APIs.",
15721577
"type": "object",

tooling/cli.rs/src/interface/rust.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ fn tauri_config_to_bundle_settings(
496496
// unwrap_or as we have a default value but used to prevent any failing
497497
dialog: updater_config.dialog,
498498
pubkey: updater_config.pubkey,
499-
endpoints: updater_config.endpoints,
499+
endpoints: updater_config
500+
.endpoints
501+
.map(|endpoints| endpoints.iter().map(|e| e.to_string()).collect()),
500502
}),
501503
..Default::default()
502504
})

0 commit comments

Comments
 (0)