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] A single, unclosed open bracken in a path will corrupt the filesystem scope permanently #11708

Closed lendle closed 13 hours ago

lendle commented 6 days ago

Describe the bug

When tauri tries to add a path the filesystem scope, if that path has an unmatched square open bracket in it, ([a.txt) the filesystem scope gets corrupted, rendering most or all fs plugin methods useless. If the persisted-scope plugin is installed, this will persist even when the app restarts. This happens with paths selected with dialog.open or if the user drag and drops a badly named file into a tauri window, even if no drag and drop event listener is registered.

Deleting $APPLOCALDATA/.persisted-scope fixes this, but does lose persisted scope info.

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. Either drag and drop a file with an unmatched open bracket in the path into the window, or selected one with in the dialog when clicking the "Click Me" button.
  4. Any time you select any file after that, you will see something like
    path: /some/path/which/may/or/may/not/have/brackets
    msg: 
    error: "invalid glob pattern: Pattern syntax error near position 11: invalid range pattern"

Expected behavior

  1. Paths with unmatched open brackets are usable
  2. Even if not, they don't permanently corrupt the scope

Full tauri info output

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

There seems to be no way to guard against this because both drag and drop and dialog open attempt to add the path to the scope immediately, so you cannot inspect the path and reject it.