#How do disallow files/directories in Tauri/FsScope?

19 messages · Page 1 of 1 (latest)

slim fog
spiral mason
#

You currently can only forbid paths not make it "forget" allowed paths. This goes both ways so for example if you forbid a path you can never allow it again

#

imo a new function that can just remove allowed and/or forbidden paths from the scope would be a super nice (and necessary) addition

#

i also thought there was a github issue about this already but i can't find it anywhere rn

slim fog
# spiral mason imo a new function that can just remove allowed and/or forbidden paths from the ...

I couldn't find the issue either but I did take a look at fs.rs and was able to implement it naively by just getting the same glob patterns for a given path and removing it from the hashmap being used, similar to how forbid works. You think this is enough to make a pull request?

Also, I saw that you made comments on a related issue with persisted-scope plugin. (https://github.com/tauri-apps/plugins-workspace/pull/32) Just thought I would mention that my approach is to instead of serializing the scope patterns and messing with regex, just serialize the path received from the FsScopeEvent and then reapplying by calling allow_x when needed. Have any thoughts?

GitHub

PR Draft for fixing #25(explanation)
Current change breaks old .persistent-scope files deserialization.
Can be fixed by moving the pattern conversion in deserialization.
Using metadata with Tauri v...

spiral mason
#

just serialize the path received from the FsScopeEvent and then reapplying by calling allow_x when needed. Have any thoughts?
iirc the allow_x / deny_x functions don't accept globs which is what this pr mainly tries to solve.

#

though i'm not 100% sure if that's actually the case or just a side effect from the escape symbol bug we've had

#

should actually investigate that stuff again before merging the pr

#

yeah, no. looking at the scope source code it should always escape the globs in allow_file, disabling globs effectively (still will actually try it just to be sure)

slim fog
#

I meant to link this one actually: https://github.com/tauri-apps/plugins-workspace/issues/25

And I meant to say that regardless of how it deals with glob patterns, the issue with the serialized pattern file exploding was solved for me by just storing the original path instead of the expanded glob patterns. This way the persisted-scope plugin could call allow_x, forbid_x with same argument that it received, if that makes sense. I don't know if that's a better approach but it works for me

GitHub

I may be mistaken as I don't know all the intricate of Tauri or Rust, but it seems to me if I use a dialog.open as a directory selector it will allow the path with allow_directory. While the cu...

spiral mason
#

ah right, i understand

#

the fix we use right now for sure isn't optimal, and ideally would not be necessary at all using your approach

#

but that's not the goal of the fix function. its primary purpose right now is to fix broken state files that already on users system

slim fog
#

I see that makes sense

spiral mason
slim fog
#

And if I could ask for some advice since you seem very knowledgeable, how do you work around writing tests for both unix/windows for a change?

spiral mason
#

Not sure i understand your question. Do you mean rust unit tests in tauri's code base? Most of these tests are platform agnostic ig

slim fog
#

Yeah, fs.rs has cfg(unix) tests. I am a noob to this so I was just wondering if it's standard practice to write / execute tests on different platforms?

let scope = new_scope();
#[cfg(unix)]
{
  scope.allow_file("/home/tauri/**").unwrap();
  assert!(scope.is_allowed("/home/tauri/**"));
  assert!(!scope.is_allowed("/home/tauri/**/file"));
  assert!(!scope.is_allowed("/home/tauri/anyfile"));
}
#[cfg(windows)]
spiral mason
#

right, that's one of the few cases where it makes sense to split it up per os because the path separator and fs root are different per os