Search code examples
chromium

How does Chromium define a System File?


After enabling chrome://flags/#native-file-system-api in my chrome 83.0.4103.61, I tried to access a folder with this new API

handle = await window.chooseFileSystemEntries({type: 'open-directory'})

I get the following error message:

error message

(Can't open this folder because it contains system files.)

Can anyone please tell me what "system files" means/how they are detected and how I could access all but these "system files"?


Solution

  • They hard code it in a source file. This link will rot once they rename the file (has already happened a couple times) so the relevant contents as of this post are:

    const struct {
      // base::BasePathKey value (or one of the platform specific extensions to it)
      // for a path that should be blocked. Specify kNoBasePathKey if |path| should
      // be used instead.
      int base_path_key;
      // Explicit path to block instead of using |base_path_key|. Set to nullptr to
      // use |base_path_key| on its own. If both |base_path_key| and |path| are set,
      // |path| is treated relative to the path |base_path_key| resolves to.
      const base::FilePath::CharType* path;
      // If this is set to kDontBlockChildren, only the given path and its parents
      // are blocked. If this is set to kBlockAllChildren, all children of the given
      // path are blocked as well. Finally if this is set to kBlockNestedDirectories
      // access is allowed to individual files in the directory, but nested
      // directories are still blocked.
      // The BlockType of the nearest ancestor of a path to check is what ultimately
      // determines if a path is blocked or not. If a blocked path is a descendent
      // of another blocked path, then it may override the child-blocking policy of
      // its ancestor. For example, if /home blocks all children, but
      // /home/downloads does not, then /home/downloads/file.ext will *not* be
      // blocked.
      BlockType type;
    } kBlockedPaths[] = {
        // Don't allow users to share their entire home directory, entire desktop or
        // entire documents folder, but do allow sharing anything inside those
        // directories not otherwise blocked.
        {base::DIR_HOME, nullptr, kDontBlockChildren},
        {base::DIR_USER_DESKTOP, nullptr, kDontBlockChildren},
        {chrome::DIR_USER_DOCUMENTS, nullptr, kDontBlockChildren},
        // Similar restrictions for the downloads directory.
        {chrome::DIR_DEFAULT_DOWNLOADS, nullptr, kDontBlockChildren},
        {chrome::DIR_DEFAULT_DOWNLOADS_SAFE, nullptr, kDontBlockChildren},
        // The Chrome installation itself should not be modified by the web.
        {chrome::DIR_APP, nullptr, kBlockAllChildren},
        // And neither should the configuration of at least the currently running
        // Chrome instance (note that this does not take --user-data-dir command
        // line overrides into account).
        {chrome::DIR_USER_DATA, nullptr, kBlockAllChildren},
        // ~/.ssh is pretty sensitive on all platforms, so block access to that.
        {base::DIR_HOME, FILE_PATH_LITERAL(".ssh"), kBlockAllChildren},
        // And limit access to ~/.gnupg as well.
        {base::DIR_HOME, FILE_PATH_LITERAL(".gnupg"), kBlockAllChildren},
    #if defined(OS_WIN)
        // Some Windows specific directories to block, basically all apps, the
        // operating system itself, as well as configuration data for apps.
        {base::DIR_PROGRAM_FILES, nullptr, kBlockAllChildren},
        {base::DIR_PROGRAM_FILESX86, nullptr, kBlockAllChildren},
        {base::DIR_PROGRAM_FILES6432, nullptr, kBlockAllChildren},
        {base::DIR_WINDOWS, nullptr, kBlockAllChildren},
        {base::DIR_APP_DATA, nullptr, kBlockAllChildren},
        {base::DIR_LOCAL_APP_DATA, nullptr, kBlockAllChildren},
        {base::DIR_COMMON_APP_DATA, nullptr, kBlockAllChildren},
        // Opening a file from an MTP device, such as a smartphone or a camera, is
        // implemented by Windows as opening a file in the temporary internet files
        // directory. To support that, allow opening files in that directory, but
        // not whole directories.
        {base::DIR_IE_INTERNET_CACHE, nullptr, kBlockNestedDirectories},
    #endif
    #if defined(OS_MAC)
        // Similar Mac specific blocks.
        {base::DIR_APP_DATA, nullptr, kBlockAllChildren},
        {base::DIR_HOME, FILE_PATH_LITERAL("Library"), kBlockAllChildren},
    #endif
    #if defined(OS_LINUX) || defined(OS_CHROMEOS)
        // On Linux also block access to devices via /dev, as well as security
        // sensitive data in /sys and /proc.
        {kNoBasePathKey, FILE_PATH_LITERAL("/dev"), kBlockAllChildren},
        {kNoBasePathKey, FILE_PATH_LITERAL("/sys"), kBlockAllChildren},
        {kNoBasePathKey, FILE_PATH_LITERAL("/proc"), kBlockAllChildren},
        // And block all of ~/.config, matching the similar restrictions on mac
        // and windows.
        {base::DIR_HOME, FILE_PATH_LITERAL(".config"), kBlockAllChildren},
        // Block ~/.dbus as well, just in case, although there probably isn't much a
        // website can do with access to that directory and its contents.
        {base::DIR_HOME, FILE_PATH_LITERAL(".dbus"), kBlockAllChildren},
    #endif
        // TODO(https://crbug.com/984641): Refine this list, for example add
        // XDG_CONFIG_HOME when it is not set ~/.config?
    };
    

    Note the bug url: https://crbug.com/984641