Skip to content

Commit 09c1993

Browse files
authored
feat: add support for Service-Woker-Allowed HTTP header (#13304)
* add support for Service-Worker-Allowed headers * add changes readme * add service_worker_allowed in to_tokens
1 parent 4221124 commit 09c1993

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": 'minor:feat'
3+
"tauri": 'minor:feat'
4+
---
5+
Adds the option to configure the HTTP `Service-Worker-Allowed` response header in `app > security > headers`

crates/tauri-cli/config.schema.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,17 @@
16781678
}
16791679
]
16801680
},
1681+
"Service-Worker-Allowed": {
1682+
"description": "The HTTP Service-Worker-Allowed response header is used to broaden the path restriction for a\n service worker's default scope.\n\n By default, the scope for a service worker registration is the directory where the service\n worker script is located. For example, if the script `sw.js` is located in `/js/sw.js`,\n it can only control URLs under `/js/` by default. Servers can use the `Service-Worker-Allowed`\n header to allow a service worker to control URLs outside of its own directory.\n\n See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Service-Worker-Allowed>",
1683+
"anyOf": [
1684+
{
1685+
"$ref": "#/definitions/HeaderSource"
1686+
},
1687+
{
1688+
"type": "null"
1689+
}
1690+
]
1691+
},
16811692
"Timing-Allow-Origin": {
16821693
"description": "The Timing-Allow-Origin response header specifies origins that are allowed to see values\n of attributes retrieved via features of the Resource Timing API, which would otherwise be\n reported as zero due to cross-origin restrictions.\n\n See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>",
16831694
"anyOf": [

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,17 @@
16781678
}
16791679
]
16801680
},
1681+
"Service-Worker-Allowed": {
1682+
"description": "The HTTP Service-Worker-Allowed response header is used to broaden the path restriction for a\n service worker's default scope.\n\n By default, the scope for a service worker registration is the directory where the service\n worker script is located. For example, if the script `sw.js` is located in `/js/sw.js`,\n it can only control URLs under `/js/` by default. Servers can use the `Service-Worker-Allowed`\n header to allow a service worker to control URLs outside of its own directory.\n\n See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Service-Worker-Allowed>",
1683+
"anyOf": [
1684+
{
1685+
"$ref": "#/definitions/HeaderSource"
1686+
},
1687+
{
1688+
"type": "null"
1689+
}
1690+
]
1691+
},
16811692
"Timing-Allow-Origin": {
16821693
"description": "The Timing-Allow-Origin response header specifies origins that are allowed to see values\n of attributes retrieved via features of the Resource Timing API, which would otherwise be\n reported as zero due to cross-origin restrictions.\n\n See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>",
16831694
"anyOf": [

crates/tauri-utils/src/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,10 @@ impl HeaderAddition for Builder {
22102210
self = self.header("Permission-Policy", value.to_string());
22112211
};
22122212

2213+
if let Some(value) = &headers.service_worker_allowed {
2214+
self = self.header("Service-Worker-Allowed", value.to_string());
2215+
}
2216+
22132217
// Add the header Timing-Allow-Origin, if we find a value for it
22142218
if let Some(value) = &headers.timing_allow_origin {
22152219
self = self.header("Timing-Allow-Origin", value.to_string());
@@ -2347,6 +2351,17 @@ pub struct HeaderConfig {
23472351
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy>
23482352
#[serde(rename = "Permissions-Policy")]
23492353
pub permissions_policy: Option<HeaderSource>,
2354+
/// The HTTP Service-Worker-Allowed response header is used to broaden the path restriction for a
2355+
/// service worker's default scope.
2356+
///
2357+
/// By default, the scope for a service worker registration is the directory where the service
2358+
/// worker script is located. For example, if the script `sw.js` is located in `/js/sw.js`,
2359+
/// it can only control URLs under `/js/` by default. Servers can use the `Service-Worker-Allowed`
2360+
/// header to allow a service worker to control URLs outside of its own directory.
2361+
///
2362+
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Service-Worker-Allowed>
2363+
#[serde(rename = "Service-Worker-Allowed")]
2364+
pub service_worker_allowed: Option<HeaderSource>,
23502365
/// The Timing-Allow-Origin response header specifies origins that are allowed to see values
23512366
/// of attributes retrieved via features of the Resource Timing API, which would otherwise be
23522367
/// reported as zero due to cross-origin restrictions.
@@ -2383,6 +2398,7 @@ impl HeaderConfig {
23832398
cross_origin_opener_policy: None,
23842399
cross_origin_resource_policy: None,
23852400
permissions_policy: None,
2401+
service_worker_allowed: None,
23862402
timing_allow_origin: None,
23872403
x_content_type_options: None,
23882404
tauri_custom_header: None,
@@ -3521,6 +3537,7 @@ mod build {
35213537
let cross_origin_opener_policy = opt_lit(self.cross_origin_opener_policy.as_ref());
35223538
let cross_origin_resource_policy = opt_lit(self.cross_origin_resource_policy.as_ref());
35233539
let permissions_policy = opt_lit(self.permissions_policy.as_ref());
3540+
let service_worker_allowed = opt_lit(self.service_worker_allowed.as_ref());
35243541
let timing_allow_origin = opt_lit(self.timing_allow_origin.as_ref());
35253542
let x_content_type_options = opt_lit(self.x_content_type_options.as_ref());
35263543
let tauri_custom_header = opt_lit(self.tauri_custom_header.as_ref());
@@ -3537,6 +3554,7 @@ mod build {
35373554
cross_origin_opener_policy,
35383555
cross_origin_resource_policy,
35393556
permissions_policy,
3557+
service_worker_allowed,
35403558
timing_allow_origin,
35413559
x_content_type_options,
35423560
tauri_custom_header

0 commit comments

Comments
 (0)