Skip to content

Commit 8d74b7a

Browse files
committed
fix: add Isolation Pattern to tauri app
- added proper security IPC Isolation Pattern - begin migratio not tauri FS API for proper path sanitization
1 parent 9e4d383 commit 8d74b7a

File tree

7 files changed

+106
-16
lines changed

7 files changed

+106
-16
lines changed

GUI/ETVR/dist-isolation/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<title>Isolation Secure Script</title>
7+
</head>
8+
9+
<body>
10+
<script src="index.js"></script>
11+
</body>
12+
13+
</html>

GUI/ETVR/dist-isolation/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
window.__TAURI_ISOLATION_HOOK__ = (payload) => {
2+
// let's not verify or modify anything, just print the content from the hook
3+
console.log('hook', payload)
4+
return payload
5+
}

GUI/ETVR/src-tauri/Cargo.lock

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GUI/ETVR/src-tauri/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ features = ["derive"]
3131

3232
[dependencies.tauri]
3333
version = "1.1.1"
34-
features = [
34+
features = [ "isolation",
3535
"protocol-asset",
3636
"fs-all",
3737
"shell-sidecar",
@@ -84,7 +84,7 @@ features = ["full"]
8484

8585
[build-dependencies.tauri-build]
8686
version = "1.1.1"
87-
features = []
87+
features = ["isolation"]
8888

8989
[profile.dev]
9090
debug = 0

GUI/ETVR/src-tauri/src/main.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ async fn close_splashscreen(window: tauri::Window) {
146146
}
147147

148148
#[tauri::command]
149-
async fn unzip_archive(archive_path: String, target_dir: String) -> Result<String, String> {
149+
async fn unzip_archive(
150+
window: tauri::Window,
151+
archive_path: String,
152+
target_dir: String,
153+
) -> Result<String, String> {
150154
// The third parameter allows you to strip away toplevel directories.
151155
// If `archive` contained a single directory, its contents would be extracted instead.
152156
let _target_dir = std::path::PathBuf::from(target_dir); // Doesn't need to exist
@@ -155,18 +159,13 @@ async fn unzip_archive(archive_path: String, target_dir: String) -> Result<Strin
155159
zip_extract::extract(std::io::Cursor::new(archive), &_target_dir, true)
156160
.expect("Failed to extract archive");
157161

158-
// erase the archive
159-
std::fs::remove_file(archive_path).expect("Failed to remove archive");
162+
// erase the archive file
163+
//window.app_handle(|app| {
164+
// let _ = app.remove_path(&archive_path);
165+
//});
160166
Ok("Archive extracted".to_string())
161167
}
162168

163-
#[tauri::command]
164-
async fn remove_archive(archive_path: String) -> Result<String, String> {
165-
// erase the archive
166-
std::fs::remove_file(archive_path).expect("Failed to remove archive");
167-
Ok("Archive removed".to_string())
168-
}
169-
170169
fn main() {
171170
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
172171
let hide = CustomMenuItem::new("hide".to_string(), "Hide");
@@ -194,8 +193,7 @@ fn main() {
194193
run_mdns_query,
195194
get_user,
196195
do_rest_request,
197-
unzip_archive,
198-
remove_archive
196+
unzip_archive
199197
])
200198
// allow only one instance and propgate args and cwd to existing instance
201199
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {

GUI/ETVR/src-tauri/tauri.conf.json

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"version": "1.0.0"
1212
},
1313
"tauri": {
14+
"pattern": {
15+
"use": "isolation",
16+
"options": {
17+
"dir": "../dist-isolation"
18+
}
19+
},
1420
"allowlist": {
1521
"all": false,
1622
"clipboard": {

GUI/ETVR/src/components/Button/EraseButton/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const EraseButton = () => {
1010
const appConfigPath = await appConfigDir()
1111
const firmwarePath = await join(appConfigPath, 'merged-firmware.bin')
1212
const manifestPath = await join(appConfigPath, 'manifest.json')
13-
await invoke('remove_archive', { archivePath: firmwarePath })
14-
await invoke('remove_archive', { archivePath: manifestPath })
13+
//await invoke('remove_archive', { archivePath: firmwarePath })
14+
//await invoke('remove_archive', { archivePath: manifestPath })
1515
}
1616

1717
return (

0 commit comments

Comments
 (0)