锁定桌面文件路径错误响应

桌面文件导出路径转换失败转为稳定不可用响应

桌面文件导入路径转换失败转为稳定不可用响应

桌面壳配置检查禁止暴露原生路径错误
This commit is contained in:
2026-06-20 12:32:45 +08:00
parent 12ab5ef064
commit 6ded19d018
2 changed files with 21 additions and 7 deletions
@@ -1086,6 +1086,20 @@ function assertDesktopDialogBoundary(method, functionName, filterLabel, expected
if (fileFunctionBody.includes(blockedDialogAction)) {
throw new Error(`desktop shell ${method} must not use ${blockedDialogAction}`);
}
const unavailableResponse =
action === 'save'
? 'Err(_) => return file_export_unavailable_response(request)'
: 'Err(_) => return file_import_unavailable_response(request)';
if (!fileFunctionBody.includes(unavailableResponse)) {
throw new Error(`desktop shell ${method} must hide native path conversion errors`);
}
if (
fileFunctionBody.includes(
'return failed(request.id.clone(), "host_error", error.to_string())',
)
) {
throw new Error(`desktop shell ${method} must not expose native path errors`);
}
}
function assertNoRawHostContextUrl(urlValue, label) {
@@ -50,7 +50,7 @@ pub(crate) async fn export_desktop_host_bridge_text_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_export_unavailable_response(request),
};
let export_result =
tauri::async_runtime::spawn_blocking(move || write_export_text_file(path, content)).await;
@@ -83,7 +83,7 @@ pub(crate) async fn import_desktop_host_bridge_text_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_import_unavailable_response(request),
};
let import_result =
tauri::async_runtime::spawn_blocking(move || import_text_file_payload(path)).await;
@@ -111,7 +111,7 @@ pub(crate) async fn import_desktop_host_bridge_document_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_import_unavailable_response(request),
};
let import_result =
tauri::async_runtime::spawn_blocking(move || import_document_file_payload(path)).await;
@@ -141,7 +141,7 @@ pub(crate) async fn export_desktop_host_bridge_image_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_export_unavailable_response(request),
};
let export_result =
tauri::async_runtime::spawn_blocking(move || write_export_bytes_file(path, bytes)).await;
@@ -173,7 +173,7 @@ pub(crate) async fn import_desktop_host_bridge_image_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_import_unavailable_response(request),
};
let import_result = tauri::async_runtime::spawn_blocking(move || {
import_image_file_payload(path, "selected", None)
@@ -200,7 +200,7 @@ pub(crate) async fn import_desktop_host_bridge_audio_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_import_unavailable_response(request),
};
let import_result =
tauri::async_runtime::spawn_blocking(move || import_audio_file_payload(path)).await;
@@ -230,7 +230,7 @@ pub(crate) async fn export_desktop_host_bridge_audio_file(
};
let path = match file_path.into_path() {
Ok(path) => path,
Err(error) => return failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => return file_export_unavailable_response(request),
};
let export_result =
tauri::async_runtime::spawn_blocking(move || write_export_bytes_file(path, bytes)).await;