Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(cowork): refuse the unsandboxed preview registration on Windows
James Damc210bd64475d
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rsindex 24dcfc175..bb8544c74 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs@@ -1058,14 +1058,15 @@ async fn execute_tool_inner(}/// Let the `preview://` scheme serve files under `root`, with `allow_network`-/// as the page policy. Re-registering the same root replaces the flag.+/// as the page policy. Re-registering the same root replaces the flag. Refused+/// on Windows; see [`PreviewRoots::register_unsandboxed`].#[tauri::command]pub fn preview_register_root(roots: tauri::State<'_, PreviewRoots>,root: String,allow_network: bool,) -> Result<(), AgentToolsError> {- roots.register(Path::new(&root), allow_network)?;+ roots.register_unsandboxed(Path::new(&root), allow_network)?;Ok(())}diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/preview.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/preview.rsindex cb7f18182..a288c7633 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/preview.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/preview.rs@@ -27,6 +27,18 @@ pub struct Served {}impl PreviewRoots {+ /// [`register`](Self::register) for the pane, which only registers a root+ /// for the unsandboxed mode (the sandboxed one is a `srcdoc` frame and never+ /// touches the scheme). Refused on Windows, where WebView2 hands this+ /// origin's frames the IPC key and the pane does not offer the mode, so+ /// nothing can be served there.+ pub fn register_unsandboxed(&self, root: &Path, allow_network: bool) -> Result<(), String> {+ if cfg!(windows) {+ return Err("ERROR: the unsandboxed preview is not available on Windows".to_string());+ }+ self.register(root, allow_network)+ }+pub fn register(&self, root: &Path, allow_network: bool) -> Result<(), String> {let canon = std::fs::canonicalize(root).map_err(|e| format!("ERROR: {e}"))?;if !canon.is_dir() {@@ -229,6 +241,18 @@ mod tests {assert!(roots.resolve(&url_path(&root.join("index.html"))).is_none());}+ #[test]+ fn the_unsandboxed_registration_is_refused_on_windows_only() {+ let root = temp_root("win");+ let roots = PreviewRoots::default();+ let registered = roots.register_unsandboxed(&root, false);+ assert_eq!(registered.is_err(), cfg!(windows));+ assert_eq!(+ roots.resolve(&url_path(&root.join("index.html"))).is_none(),+ cfg!(windows)+ );+ }+#[test]fn registering_a_missing_root_errors() {let roots = PreviewRoots::default();