Skip to content

Commit f284f9c

Browse files
authored
refactor: configure URLs instead of domains on capability remote (#8898)
1 parent 8d16a80 commit f284f9c

10 files changed

Lines changed: 91 additions & 45 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-utils": patch:breaking
3+
"tauri": patch:breaking
4+
---
5+
6+
Changed the capability `remote` configuration to take a list of `urls` instead of `domains` for more flexibility.

core/tauri-config-schema/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,10 @@
11511151
"remote": {
11521152
"type": "object",
11531153
"required": [
1154-
"domains"
1154+
"urls"
11551155
],
11561156
"properties": {
1157-
"domains": {
1157+
"urls": {
11581158
"description": "Remote domains this capability refers to. Can use glob patterns.",
11591159
"type": "array",
11601160
"items": {

core/tauri-utils/src/acl/capability.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub enum CapabilityContext {
9999
/// Capability refers to remote usage.
100100
Remote {
101101
/// Remote domains this capability refers to. Can use glob patterns.
102-
domains: Vec<String>,
102+
urls: Vec<String>,
103103
},
104104
}
105105

@@ -159,9 +159,9 @@ mod build {
159159
let prefix = quote! { ::tauri::utils::acl::capability::CapabilityContext };
160160

161161
tokens.append_all(match self {
162-
Self::Remote { domains } => {
163-
let domains = vec_lit(domains, str_lit);
164-
quote! { #prefix::Remote { domains: #domains } }
162+
Self::Remote { urls } => {
163+
let urls = vec_lit(urls, str_lit);
164+
quote! { #prefix::Remote { urls: #urls } }
165165
}
166166
Self::Local => {
167167
quote! { #prefix::Local }

core/tauri-utils/src/acl/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ pub enum ExecutionContext {
189189
Local,
190190
/// Remote URL is tring to use the IPC.
191191
Remote {
192-
/// The domain trying to access the IPC (glob pattern).
193-
domain: Pattern,
192+
/// The URL trying to access the IPC (glob pattern).
193+
url: Pattern,
194194
},
195195
}
196196

@@ -212,9 +212,9 @@ mod build_ {
212212
Self::Local => {
213213
quote! { #prefix::Local }
214214
}
215-
Self::Remote { domain } => {
216-
let domain = domain.as_str();
217-
quote! { #prefix::Remote { domain: #domain.parse().unwrap() } }
215+
Self::Remote { url } => {
216+
let url = url.as_str();
217+
quote! { #prefix::Remote { url: #url.parse().unwrap() } }
218218
}
219219
});
220220
}

core/tauri-utils/src/acl/resolved.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ fn resolve_command(
349349
CapabilityContext::Local => {
350350
vec![ExecutionContext::Local]
351351
}
352-
CapabilityContext::Remote { domains } => domains
352+
CapabilityContext::Remote { urls } => urls
353353
.iter()
354-
.map(|domain| ExecutionContext::Remote {
355-
domain: Pattern::new(domain)
356-
.unwrap_or_else(|e| panic!("invalid glob pattern for remote domain {domain}: {e}")),
354+
.map(|url| ExecutionContext::Remote {
355+
url: Pattern::new(url)
356+
.unwrap_or_else(|e| panic!("invalid glob pattern for remote URL {url}: {e}")),
357357
})
358358
.collect(),
359359
};

core/tauri/src/ipc/authority.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ pub enum Origin {
3535
Local,
3636
/// Remote origin.
3737
Remote {
38-
/// Remote origin domain.
39-
domain: String,
38+
/// Remote URL.
39+
url: String,
4040
},
4141
}
4242

4343
impl Display for Origin {
4444
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4545
match self {
4646
Self::Local => write!(f, "local"),
47-
Self::Remote { domain } => write!(f, "remote: {domain}"),
47+
Self::Remote { url } => write!(f, "remote: {url}"),
4848
}
4949
}
5050
}
@@ -53,12 +53,9 @@ impl Origin {
5353
fn matches(&self, context: &ExecutionContext) -> bool {
5454
match (self, context) {
5555
(Self::Local, ExecutionContext::Local) => true,
56-
(
57-
Self::Remote { domain },
58-
ExecutionContext::Remote {
59-
domain: domain_pattern,
60-
},
61-
) => domain_pattern.matches(domain),
56+
(Self::Remote { url }, ExecutionContext::Remote { url: url_pattern }) => {
57+
url_pattern.matches(url)
58+
}
6259
_ => false,
6360
}
6461
}
@@ -292,7 +289,7 @@ impl RuntimeAuthority {
292289
.map(|(cmd, resolved)| {
293290
let context = match &cmd.context {
294291
ExecutionContext::Local => "[local]".to_string(),
295-
ExecutionContext::Remote { domain } => format!("[remote: {}]", domain.as_str()),
292+
ExecutionContext::Remote { url } => format!("[remote: {}]", url.as_str()),
296293
};
297294
format!(
298295
"- context: {context}, referenced by: {}",
@@ -634,11 +631,11 @@ mod tests {
634631

635632
#[test]
636633
fn remote_domain_matches() {
637-
let domain = "tauri.app";
634+
let url = "https://tauri.app";
638635
let command = CommandKey {
639636
name: "my-command".into(),
640637
context: ExecutionContext::Remote {
641-
domain: Pattern::new(domain).unwrap(),
638+
url: Pattern::new(url).unwrap(),
642639
},
643640
};
644641
let window = "main";
@@ -666,21 +663,19 @@ mod tests {
666663
&command.name,
667664
window,
668665
webview,
669-
&Origin::Remote {
670-
domain: domain.into()
671-
}
666+
&Origin::Remote { url: url.into() }
672667
),
673668
Some(&resolved_cmd)
674669
);
675670
}
676671

677672
#[test]
678673
fn remote_domain_glob_pattern_matches() {
679-
let domain = "tauri.*";
674+
let url = "http://tauri.*";
680675
let command = CommandKey {
681676
name: "my-command".into(),
682677
context: ExecutionContext::Remote {
683-
domain: Pattern::new(domain).unwrap(),
678+
url: Pattern::new(url).unwrap(),
684679
},
685680
};
686681
let window = "main";
@@ -709,7 +704,7 @@ mod tests {
709704
window,
710705
webview,
711706
&Origin::Remote {
712-
domain: domain.replace('*', "studio")
707+
url: url.replace('*', "studio")
713708
}
714709
),
715710
Some(&resolved_cmd)
@@ -748,7 +743,7 @@ mod tests {
748743
window,
749744
webview,
750745
&Origin::Remote {
751-
domain: "tauri.app".into()
746+
url: "https://tauri.app".into()
752747
}
753748
)
754749
.is_none());

core/tauri/src/webview/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,10 +1113,7 @@ fn main() {
11131113
Origin::Local
11141114
} else {
11151115
Origin::Remote {
1116-
domain: current_url
1117-
.domain()
1118-
.map(|d| d.to_string())
1119-
.unwrap_or_default(),
1116+
url: current_url.to_string(),
11201117
}
11211118
};
11221119
let resolved_acl = manager

core/tests/acl/fixtures/capabilities/file-explorer-remote/cap.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ description = "app capability"
33
windows = ["main"]
44
permissions = ["fs:read", "fs:allow-app"]
55
[context.remote]
6-
domains = ["tauri.app"]
6+
urls = ["https://tauri.app"]

core/tests/acl/fixtures/snapshots/acl_tests__tests__file-explorer-remote.snap

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,33 @@ Resolved {
77
CommandKey {
88
name: "plugin:fs|read_dir",
99
context: Remote {
10-
domain: Pattern {
11-
original: "tauri.app",
10+
url: Pattern {
11+
original: "https://tauri.app",
1212
tokens: [
13+
Char(
14+
'h',
15+
),
16+
Char(
17+
't',
18+
),
19+
Char(
20+
't',
21+
),
22+
Char(
23+
'p',
24+
),
25+
Char(
26+
's',
27+
),
28+
Char(
29+
':',
30+
),
31+
Char(
32+
'/',
33+
),
34+
Char(
35+
'/',
36+
),
1337
Char(
1438
't',
1539
),
@@ -68,9 +92,33 @@ Resolved {
6892
CommandKey {
6993
name: "plugin:fs|read_file",
7094
context: Remote {
71-
domain: Pattern {
72-
original: "tauri.app",
95+
url: Pattern {
96+
original: "https://tauri.app",
7397
tokens: [
98+
Char(
99+
'h',
100+
),
101+
Char(
102+
't',
103+
),
104+
Char(
105+
't',
106+
),
107+
Char(
108+
'p',
109+
),
110+
Char(
111+
's',
112+
),
113+
Char(
114+
':',
115+
),
116+
Char(
117+
'/',
118+
),
119+
Char(
120+
'/',
121+
),
74122
Char(
75123
't',
76124
),

tooling/cli/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,10 @@
11511151
"remote": {
11521152
"type": "object",
11531153
"required": [
1154-
"domains"
1154+
"urls"
11551155
],
11561156
"properties": {
1157-
"domains": {
1157+
"urls": {
11581158
"description": "Remote domains this capability refers to. Can use glob patterns.",
11591159
"type": "array",
11601160
"items": {

0 commit comments

Comments
 (0)