window.showDirectoryPicker opens up a whole new world

2 hours ago (steveharrison.dev)

So websites can now nag users to allow access to the root of their local disk and then read all their files and settings, all their SSH keys and other passwords?

From what I gather from the docs [1], this API gives you a FileSystemDirectoryHandle object, and then you just call getDirectoryHandle() on that to recursively read the the entire filesystem. The spec [2] has some vague suggestions about blacklisting certain particularly sensitive files, which doesn't seem reassuring.

[1] https://developer.chrome.com/docs/capabilities/web-apis/file...

[2] https://wicg.github.io/file-system-access/#privacy-wide-acce...

  • Root directory would be on that blacklist for sure.

    Those "vague suggestions" actually seem to include some pretty specific examples.

    > A user’s entire "home" directory. Individual files and directories inside the home directory should still be allowed, but user agents should not generally let users give blanket access to the entire directory.

  • Let's not forget that, at the same time, Google forces every developer of any Android app to register in the Google database using an ID scan, otherwise no one can install it.

    All for the sake of "dear user safety".

This isn't new, the API has been around for several years. Unfortunately Mozilla and Apple say they are never going to implement it because of security concerns https://github.com/mozilla/standards-positions/issues/154

It is a great API though, I wish the other browser vendors liked it! Because currently us PWA developers are really limited when trying to make apps that work with local data, at least in non-Chrome browsers.

  • I'd love for Google to figure out something comparable for the Drive API (currently it's not possible to grant read/write access to a single folder; you need to grant access to the entire drive!): https://issuetracker.google.com/issues/36760598?pli=1

    I think the fact that the above issue has been open for a very long time is one indication of how difficult and sensitive this type of access control API is. The Google Drive API could be a proving ground for getting the UX right for this (including tricky details like how to manage persistent access to a folder with clear disclosure and user controls).

    • Is it really that complicated?

      Why not just create per-domain browser-controlled folders (cert-linked?) that are abstracted into a simple read/write API via the browser (with subfolders allowed under that domain's root), disallow cross-domain access... and then build browser-mediated linking for use cases where you want to flow files from (non-domain) to (domain) to (non-domain)?

      So essentially local storage with better integration with the actual filesystem, that's browser-controlled.

      Allowing websites to have arbitrary (even user-approved) access directly to the real filesystem seems like a bad idea, when most use cases could be handled by a browser-mediated filesystem-like abstract view.

  • You could implement it this way:

    - the first time you select a directory it must be empty

    - you can drag files in there afterwards

    - the directory gets whitelisted for future use

    Probably has bad usability, but would be more secure.

I think something that is a mix between localStorage or IndexedDB and access to the user's filesystem would be better.

I agree with the comments about how much of a security risk this poses. But, isn't that the case with any binary or executable files and apps we download from the internet anyway?

It would be cool if you could have a specially-demarcated directory (e.g. even inside the application like `~/Applications/Chrome/<website>/local_files`) which you can just open super easily with a button from Chrome, and just copy files over into that directory as needed. Would provide the benefits of a more secure enclave with the flexibility of being on the filesystem.

it's a bit of a shame that TFA does not mention that this is a non-standard API pushed by google only (all three editors of the draft are google engineers)

everyone else is opposed to it: - Mozilla: https://mozilla.github.io/standards-positions/#native-file-s... - Apple: https://webkit.org/standards-positions/#position-28

encouraging people to build apps that only work in google web browsers actively harms the web and sends a signal to google that they can in fact keep doing this

I'm not sure if this is meant to be ironic?

"You can also create folders within the app and move photos into them, and it all happens on your filesystem."

Why, yes. But you can also do that with Finder.

And if you want to work with local data, why use the often inferior web-based widgets and toolkits instead of native ones?

This seems to be the worst of both worlds so to speak.

  • I used to think like this too, but somewhat surprisingly to myself, I have actually come around to deciding the web API is the most user-forward API that closed-source software can target, and it is actually good for end users for closed-source software to target it. This is because web API software is distributed as plaintext to be interpreted by software under user's control, the browser. This gives a ton of power to the user. We as end users can develop browser extensions, CSS hacks, and so on, to make this closed-source software work better for us.

    I frequently do this; why can't I paste into this password text box? Screw it, I go into dev tools and enable pasting into it. Who decided grey-on-grey text was a good idea? Screw it, I got into dev tools and make the text black. Why can't I copy the text on this page? Screw it, I go into dev tools and yank it straight from the DOM. Why does this stupid animation take so long? Screw it, I go develop a greasemonkey script to set the animation timer value to 0. This is all quite easy with web API software, but would be be extremely difficult with a compiled binary.

    I think it is also a good choice for open-source software for the same reason. It provides a common, well-tooled API for users to hack the software they are using. But open-source software has other hackable options that make it less of a strong argument there.

    Native toolkits definitely have a lot of nice features that the web API doesn't (yet) have, and there's a ton of value in the consistency native toolkits provide. But I think I've come around to valuing hackability over those features, so I'm actually now a web API fan. Again, surprising myself with this switch :)

  • The best app is the one that is available on your platform.

    Unfortunately I think the ubiquity of browser-based web apps are the only reason the Linux desktop is even remotely usable at this point.

First time I've heard about this. I'll have to look into the security model around it. I'm curious what safeguards are in place to prevent click jacking. I know showing a file picker """should""" be enough of a warning to users to be careful, but it's not hard to imagine a world where a couple of fish accidentally bite the bait of an allow-button, or because they followed instructions they incorrectly trusted.

  • Looks like these safeguards are in place:

    * System and root directories cannot be selected. * Can only being activated after user action. * Requires https. * Double-confirmation for write access.

    No API like this could ever be bulletproof, but it's a start I guess.

    Very cool API though, and it really does open up a whole new world of possibilities.

    • Those are some pretty flimsy safeguards. I don't keep my secrets in system directories and using HTTPS doesn't mean the site isn't malicious.

      1 reply →

    • > System and root directories cannot be selected.

      That desperately needs something like the Public Suffix List [1] - a community-managed list where authors of software can blacklist directories containing sensitive files or such files directly for all browsers implementing this feature.

      If I were to design such a list, it would include ~/.ssh, ~/.aws, ~/.config, ~/Library, ~/.{ba,z}sh{rc,_profile,_history}, ~/.m2, ~/.npm, ~/.npmrc, ~/.profile at the very least. Because users will get phished.

      [1] https://en.wikipedia.org/wiki/Public_Suffix_List

      1 reply →

  • This is something you should explain to the Firefox critics.

    • Chrome and friends (Edge, Opera) are basically the new IE6 and only people who are new or forgetful will disagree. I hate Mozilla for missing up so bad with their stewardship of Firefox time and again, but alas, it is the only reasonable option on the table.

      And while I do hate Mozilla, Google is to be disliked even more.

I'm really excited about window.showDirectoryPicker and the local-first web apps it will enable. There's lots of talk about local-first sync engines, but the best sync engine is one you don't even manage, like the user's file system / cloud storage service!

  • [flagged]

    • Firefox may not be the best browser, but it's the last full-featured non-commercial independent browser still available (excluding forks like Waterfox).

      If we want a free and open internet, we need to protect Firefox at all costs.

      3 replies →

Too many prompts and not an official API. Back in the day, IE also had tons of "great" and novel ideas, including COM+ something something.

  • They also popularized XMLHttpRequest. Sometimes a flexible idea can trend to the greater ecosystem.

Some of the permissions problems related to window.showDirectoryPicker have been frustrating. I'm developing a client-side Python web framework, and during development I need to mount the library locally; I hand off the directory to Pyodide using this API. But that doesn't work in VSCode's internal browser, apparently because the API just simply isn't able to be approved.

But webkitdirectory="true" could already do that, no?

  • No, they're very different. Using webkitdirectory="true" on an <input> element just allows you to select a directory to e.g. upload it to the server. It's a one-time operation.

    This API returns a handle to the selected directory, giving the webpage ongoing read/write access to the directory.

    You couldn't use the former to e.g. create a local-first notes app that stores its files on disk.

Currently using this in socket2.me

Not truly supported across all mobile browser currently, but it's certainly better than just one year ago.

Phishers and exploit developers are celebrating and jumping for joy over yet another way to deploy their payload to their victims.

What are the many ways could this possibly go wrong?

I wish we had this in the operating system. It would solve an immense number of risks such as data deletion from bugs and even ransomware.

  • Which operating system do you mean? Flatpak has this already, Android enforces this kind of API for shared files, Windows UWP has pretty much the exact same API (https://learn.microsoft.com/en-us/uwp/api/windows.storage.pi...).

    App developers will often choose not to sandbox their applications because it's a lot easier (and sometimes faster) do to all file management yourself, but the APIs are there and ready to be used.

    • Flatpak is probably the worst way to "have" this possible. It's completely opaque to both app and user. If you ever tried to run an .exe through flatpak'd bottles, you'll run into an issue where .dll's aren't found because you didn't install flatseal first to configure permissions. That's not operating-system level integration. That is actually very poor design that a user requires a separate app (flatseal) to configure how the sandbox works.

      I was thinking about desktop OS's, actually.

      You don't need to use that Windows API. You can just access any file you want. There is no reason a music player, for example, needs to access ~/Pictures. An arbitrary program requiring access to all your files is a huge red flag, but it's a red flag that users aren't allowed to see. Proper filesystem permissions would fix that.

  • MacOS has this and what happens is that you get into the habit of just clicking through it. It won't help with ransomware, only backups would.

> Chrome introduced a new API, window.showDirectoryPicker() that allows the user to grant access to a directory on their computer and allow a website to read/write everything inside.

I mean, what could go wrong?

It's not like an user is tricked into uploading a file from a folder (let's say, the main "Documents" folder) and some malicious website steals all the files over there.

  • If you tried this out in Linux, for example, the system would block you from selecting folders that contain files that are flagged as dangerous or "system files". I'm assuming this was implemented across all OSes.

    • That does not sound at all reassuring, that the only safeguard is the system blocking access and that the API has no safeguard.

      Its also easily possible to have sensitive files misplaced, especially for a general non-technical user that would be the one falling for a browser hijacking attack

      1 reply →

    • i give zero F about whatever is in my /usr, /var/lib and /opt folders.

      what are websites gonna steal, debian binaries and libraries?

      all my important stuff are in my home directory, which is owned (read+write) by me, the same user running the browser.