tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.36k stars 2.58k forks source link

[bug] Paths with open an close square brackets [] in the path are not correctely added to accessible scope #11707

Closed lendle closed 13 hours ago

lendle commented 5 days ago

Describe the bug

If a path has square brackets in it, e.g. /path/[to]/a.txt or /path/to/[a].txt, then that path will not work with fs plugin methods. Even if the path is selected with dialog.open, which should add selected path to allowed scope.

Reproduction

Example project: https://github.com/lendle/tauri-app-bad-filenames

  1. Run the app in dev mode
  2. Click the button, select any file that does not have square brackets in the path. You will see something like
    path: /path/to/a.txt
    msg: /path/to/a.txt exists: true
    error: 
  3. Click the button, select a file with matching brackets in the path, like [a].txt. You will see
    
    path: /path/to/[a].txt
    msg: 
    error: "forbidden path: /path/to/[a].txt"

### Expected behavior

Paths with square brackets should be correctly added to allowed scope

### Full `tauri info` output

```text
npm run tauri info

> tauri-app-bad-filenames@0.1.0 tauri
> tauri info

[✔] Environment
    - OS: Mac OS 14.6.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.79.0 (129f3b996 2024-06-10)
    ✔ cargo: 1.79.0 (ffa9cf99a 2024-06-03)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: 1.79.0-aarch64-apple-darwin (default)
    - node: 22.5.1
    - npm: 10.8.3

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.0
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.1.1
    - @tauri-apps/cli : 2.1.0

[-] Plugins
    - tauri-plugin-fs 🦀: 2.0.3
    - @tauri-apps/plugin-fs : 2.0.2
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.1
    - tauri-plugin-persisted-scope 🦀: 2.0.3
    - @tauri-apps/plugin-persisted-scope : not installed!
    - tauri-plugin-dialog 🦀: 2.0.3
    - @tauri-apps/plugin-dialog : 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

Stack trace

No response

Additional context

No response