Skip to content

Commit 82169e6

Browse files
authored
fix(core): remove trailing slash in http scope url, closes #5208 (#6974)
* fix(core): remove trailing slash in http scope url, closes #5208 * fix tests * one more tests fix * clippy
1 parent aecf146 commit 82169e6

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

.changes/config-scope-url.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'patch'
3+
---
4+
5+
Fix parsing `allowlist > http > scope` urls that added a trailing slash which broke matching the incoming requests url.

core/tauri-config-schema/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@
24312431
"additionalProperties": false
24322432
},
24332433
"HttpAllowlistScope": {
2434-
"description": "HTTP API scope definition. It is a list of URLs that can be accessed by the webview when using the HTTP APIs. The scoped URL is matched against the request URL using a glob pattern.\n\nExamples: - \"https://**\": allows all HTTPS urls - \"https://*.github.com/tauri-apps/tauri\": allows any subdomain of \"github.com\" with the \"tauri-apps/api\" path - \"https://myapi.service.com/users/*\": allows access to any URLs that begins with \"https://myapi.service.com/users/\"",
2434+
"description": "HTTP API scope definition. It is a list of URLs that can be accessed by the webview when using the HTTP APIs. The scoped URL is matched against the request URL using a glob pattern.\n\nExamples: - \"https://*\": allows all HTTPS urls - \"https://*.github.com/tauri-apps/tauri\": allows any subdomain of \"github.com\" with the \"tauri-apps/api\" path - \"https://myapi.service.com/users/*\": allows access to any URLs that begins with \"https://myapi.service.com/users/\"",
24352435
"type": "array",
24362436
"items": {
24372437
"type": "string",

core/tauri-utils/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,11 +1892,13 @@ impl Allowlist for DialogAllowlistConfig {
18921892
/// The scoped URL is matched against the request URL using a glob pattern.
18931893
///
18941894
/// Examples:
1895-
/// - "https://**": allows all HTTPS urls
1895+
/// - "https://*": allows all HTTPS urls
18961896
/// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
18971897
/// - "https://myapi.service.com/users/*": allows access to any URLs that begins with "https://myapi.service.com/users/"
18981898
#[allow(rustdoc::bare_urls)]
18991899
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
1900+
// TODO: in v2, parse into a String or a custom type that perserves the
1901+
// glob string because Url type will add a trailing slash
19001902
#[cfg_attr(feature = "schema", derive(JsonSchema))]
19011903
pub struct HttpAllowlistScope(pub Vec<Url>);
19021904

core/tauri/src/scope/http.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@ impl Scope {
1919
allowed_urls: scope
2020
.0
2121
.iter()
22-
.map(|url| {
23-
glob::Pattern::new(url.as_str())
24-
.unwrap_or_else(|_| panic!("scoped URL is not a valid glob pattern: `{url}`"))
22+
.flat_map(|url| {
23+
[
24+
glob::Pattern::new(url.as_str())
25+
.unwrap_or_else(|_| panic!("scoped URL is not a valid glob pattern: `{url}`")),
26+
glob::Pattern::new(
27+
url
28+
.as_str()
29+
.strip_suffix('/')
30+
.unwrap_or_else(|| url.as_str()),
31+
)
32+
.unwrap_or_else(|_| panic!("scoped URL is not a valid glob pattern: `{url}`")),
33+
]
2534
})
2635
.collect(),
2736
}
@@ -81,7 +90,7 @@ mod tests {
8190
let scope = super::Scope::for_http_api(&HttpAllowlistScope(vec!["http://*".parse().unwrap()]));
8291

8392
assert!(scope.is_allowed(&"http://something.else".parse().unwrap()));
84-
assert!(!scope.is_allowed(&"http://something.else/path/to/file".parse().unwrap()));
93+
assert!(scope.is_allowed(&"http://something.else/path/to/file".parse().unwrap()));
8594
assert!(!scope.is_allowed(&"https://something.else".parse().unwrap()));
8695

8796
let scope = super::Scope::for_http_api(&HttpAllowlistScope(vec!["http://**".parse().unwrap()]));

tooling/cli/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@
24312431
"additionalProperties": false
24322432
},
24332433
"HttpAllowlistScope": {
2434-
"description": "HTTP API scope definition. It is a list of URLs that can be accessed by the webview when using the HTTP APIs. The scoped URL is matched against the request URL using a glob pattern.\n\nExamples: - \"https://**\": allows all HTTPS urls - \"https://*.github.com/tauri-apps/tauri\": allows any subdomain of \"github.com\" with the \"tauri-apps/api\" path - \"https://myapi.service.com/users/*\": allows access to any URLs that begins with \"https://myapi.service.com/users/\"",
2434+
"description": "HTTP API scope definition. It is a list of URLs that can be accessed by the webview when using the HTTP APIs. The scoped URL is matched against the request URL using a glob pattern.\n\nExamples: - \"https://*\": allows all HTTPS urls - \"https://*.github.com/tauri-apps/tauri\": allows any subdomain of \"github.com\" with the \"tauri-apps/api\" path - \"https://myapi.service.com/users/*\": allows access to any URLs that begins with \"https://myapi.service.com/users/\"",
24352435
"type": "array",
24362436
"items": {
24372437
"type": "string",

0 commit comments

Comments
 (0)