瀏覽代碼

feat(core): use a strict CSP on the isolation iframe (#9075)

Lucas Fernandes Nogueira 1 年之前
父節點
當前提交
7cec1049e8
共有 3 個文件被更改,包括 9 次插入0 次删除
  1. 5 0
      .changes/strict-isolation-csp.md
  2. 3 0
      core/tauri/src/protocol/isolation.rs
  3. 1 0
      examples/api/src-tauri/Cargo.lock

+ 5 - 0
.changes/strict-isolation-csp.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch:enhance
+---
+
+Use a strict content security policy on the isolation pattern HTML.

+ 3 - 0
core/tauri/src/protocol/isolation.rs

@@ -10,6 +10,8 @@ use std::sync::Arc;
 
 use crate::{manager::webview::PROCESS_IPC_MESSAGE_FN, webview::UriSchemeProtocolHandler};
 
+const CSP: &str = "default-src: 'none'";
+
 pub fn get(assets: Arc<EmbeddedAssets>, aes_gcm_key: [u8; 32]) -> UriSchemeProtocolHandler {
   Box::new(move |request, responder| {
     let response = match request_to_path(&request).as_str() {
@@ -23,6 +25,7 @@ pub fn get(assets: Arc<EmbeddedAssets>, aes_gcm_key: [u8; 32]) -> UriSchemeProto
           match template.render(asset.as_ref(), &Default::default()) {
             Ok(asset) => http::Response::builder()
               .header(CONTENT_TYPE, mime::TEXT_HTML.as_ref())
+              .header("Content-Security-Policy", CSP)
               .body(asset.into_string().as_bytes().to_vec()),
             Err(_) => http::Response::builder()
               .status(http::StatusCode::INTERNAL_SERVER_ERROR)

+ 1 - 0
examples/api/src-tauri/Cargo.lock

@@ -3302,6 +3302,7 @@ dependencies = [
  "gtk",
  "http",
  "jni",
+ "log",
  "percent-encoding",
  "raw-window-handle 0.6.0",
  "softbuffer",