Skip to content

Commit f5efc24

Browse files
committed
fix(core): runtime CSP changes on Linux
1 parent 36ca392 commit f5efc24

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

.changes/fix-csp-linux.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fix CSP usage on Linux when changing it via the `on_web_resource_request` handler.

core/tauri/src/manager.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ fn set_csp<R: Runtime>(
126126
default_src.push(format_real_schema(schema));
127127
}
128128

129-
#[allow(clippy::let_and_return)]
130-
let csp = Csp::DirectiveMap(csp).to_string();
131-
#[cfg(target_os = "linux")]
132-
{
133-
*asset = set_html_csp(asset, &csp);
134-
}
135-
csp
129+
Csp::DirectiveMap(csp).to_string()
136130
}
137131

138132
#[cfg(target_os = "linux")]
@@ -826,13 +820,16 @@ impl<R: Runtime> WindowManager<R> {
826820

827821
// if it's an HTML file, we need to set the CSP meta tag on Linux
828822
#[cfg(target_os = "linux")]
829-
if let (Some(original_csp), Some(response_csp)) = (
830-
asset.csp_header,
831-
response.headers().get("Content-Security_Policy"),
832-
) {
823+
if let Some(response_csp) = response.headers().get("Content-Security-Policy") {
833824
let response_csp = String::from_utf8_lossy(response_csp.as_bytes());
834-
if response_csp != original_csp {
835-
let body = set_html_csp(&String::from_utf8_lossy(response.body()), &response_csp);
825+
let body = set_html_csp(&String::from_utf8_lossy(response.body()), &response_csp);
826+
*response.body_mut() = body.as_bytes().to_vec();
827+
}
828+
} else {
829+
#[cfg(target_os = "linux")]
830+
{
831+
if let Some(csp) = &asset.csp_header {
832+
let body = set_html_csp(&String::from_utf8_lossy(response.body()), csp);
836833
*response.body_mut() = body.as_bytes().to_vec();
837834
}
838835
}

0 commit comments

Comments
 (0)