Verified Commit 06987a39 authored by Ray Kraesig's avatar Ray Kraesig Committed by ma1
Browse files

Bug 1950056 - extend use of FOS_NODEREFERENCELINKS r=Gijs,win-reviewers,gstoll

In the modern era of user-customizable Quick Access sidebars on every
file dialog, navigating via `.lnk` files is rather less useful than it
was twenty years ago.

Disable link-following in file-open dialogs by default, to prevent any
of the usual security issues involving symlink smuggling. Allow
overriding this behavior via a pref, for users who don't care.

(File-save dialogs have a more nuanced guard against that sort of thing;
this patch doesn't affect that.)

Differential Revision: https://phabricator.services.mozilla.com/D239833
parent 3ce005c0
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -15784,6 +15784,17 @@
  value: 0
  mirror: always

# Whether to follow `.lnk` (etc.) shortcuts in the Windows file-open dialog.
#
# Valid values:
#  * 0: never
#  * 1: always
#  * 2: auto
- name: widget.windows.follow_shortcuts_on_file_open
  type: RelaxedAtomicInt32
  value: 2
  mirror: always

# The number of messages of each type to keep for display in
# about:windows-messages
- name: widget.windows.messages_to_log
+18 −7
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WindowsVersion.h"
#include "nsReadableUtils.h"
@@ -181,19 +182,29 @@ bool nsFilePicker::ShowFilePicker(const nsString& aInitialDir) {

    // mode specific
    switch (mMode) {
      case modeOpenMultiple:
        fos |= FOS_ALLOWMULTISELECT;
        [[fallthrough]];

      case modeOpen:
        fos |= FOS_FILEMUSTEXIST;
        switch (mozilla::StaticPrefs::
                    widget_windows_follow_shortcuts_on_file_open()) {
          case 1:
            break;

      case modeOpenMultiple:
        fos |= FOS_FILEMUSTEXIST | FOS_ALLOWMULTISELECT;
          default:
            fos |= FOS_NODEREFERENCELINKS;
        }
        break;

      case modeSave:
        fos |= FOS_NOREADONLYRETURN;
        // Don't follow shortcuts when saving a shortcut, this can be used
        // to trick users (bug 271732)
        if (IsDefaultPathLink()) fos |= FOS_NODEREFERENCELINKS;
        // Don't follow shortcuts when saving a shortcut; this can be used to
        // trick users (bug 271732). _Do_ follow shortcuts when not saving a
        // shortcut (bug 283730).
        if (IsDefaultPathLink()) {
          fos |= FOS_NODEREFERENCELINKS;
        }
        break;

      case modeGetFolder: