Open mildred opened 1 month ago
In v2 the scope config belongs in the capability json file in src-tauri/capabilities/
now, not into the tauri.conf.json file: https://v2.tauri.app/plugin/file-system/#permissions
Using "**"
should allow all paths (btw, you can also allow paths dynamically in rust using app.fs_scope().allow_file(path)
).
That said, relative paths (relative to the app) in the frontend are a bit tricky, so it may not be working with the correct scope either. Please reach out again here if that's the case.
Relative paths is exactly the problem I was experiencing...
Forbidden path ./path/to/file
I added "**"
to the scope but I still get the Forbidden path error...
I added this command to main.rs
:
use tauri::{AppHandle, Runtime};
use tauri_plugin_fs::FsExt;
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn allow_file<R: Runtime>(
app: AppHandle<R>,
path: &str) -> () {
app.fs_scope().allow_file(path);
}
Then made use of it in javascript:
import { invoke } from '@tauri-apps/api/core'
import { getMatches } from '@tauri-apps/plugin-cli'
import { readTextFile } from '@tauri-apps/plugin-fs';
console.log("CLI arg: %o", matches)
if (matches.args.filename) {
let path = matches.args.filename.value
await invoke("allow_file", { path })
const html = await readTextFile(path)
if (html != null) {
setContent(html)
}
}
Describe the bug
I have an application that needs to open up files present on the command-line, however the security restrictions seems to prevent that.
I get a
Forbidden path ./path/to/file
when I try to run fs.readTextFile()Reproduction
Setup a Tauri v2 app with in config:
Then try to run the following javascript code:
Expected behavior
You get a forbidden path error
Full
tauri info
outputStack trace
No response
Additional context
No response