mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-15 05:31:42 +03:00
fix(core): runtime CSP changes on Linux
This commit is contained in:
parent
36ca392f38
commit
f5efc248da
5
.changes/fix-csp-linux.md
Normal file
5
.changes/fix-csp-linux.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Fix CSP usage on Linux when changing it via the `on_web_resource_request` handler.
|
@ -126,13 +126,7 @@ fn set_csp<R: Runtime>(
|
||||
default_src.push(format_real_schema(schema));
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
let csp = Csp::DirectiveMap(csp).to_string();
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
*asset = set_html_csp(asset, &csp);
|
||||
}
|
||||
csp
|
||||
Csp::DirectiveMap(csp).to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -826,13 +820,16 @@ impl<R: Runtime> WindowManager<R> {
|
||||
|
||||
// if it's an HTML file, we need to set the CSP meta tag on Linux
|
||||
#[cfg(target_os = "linux")]
|
||||
if let (Some(original_csp), Some(response_csp)) = (
|
||||
asset.csp_header,
|
||||
response.headers().get("Content-Security_Policy"),
|
||||
) {
|
||||
if let Some(response_csp) = response.headers().get("Content-Security-Policy") {
|
||||
let response_csp = String::from_utf8_lossy(response_csp.as_bytes());
|
||||
if response_csp != original_csp {
|
||||
let body = set_html_csp(&String::from_utf8_lossy(response.body()), &response_csp);
|
||||
let body = set_html_csp(&String::from_utf8_lossy(response.body()), &response_csp);
|
||||
*response.body_mut() = body.as_bytes().to_vec();
|
||||
}
|
||||
} else {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if let Some(csp) = &asset.csp_header {
|
||||
let body = set_html_csp(&String::from_utf8_lossy(response.body()), csp);
|
||||
*response.body_mut() = body.as_bytes().to_vec();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user