Skip to content

Commit b4e69c6

Browse files
ltrzesniewskiDHowett
authored andcommitted
Add safeUriSchemes setting (#20207)
This adds a `safeUriSchemes` global setting which lets you define hyperlink URI schemes which the user considers safe. No confirmation dialog will be shown when trying to open hyperlinks which use these schemes. - This solves the root issue, but doesn't introduce any UI or documentation changes. I wanted to validate the approach and implementation with you first. - I closely followed the code handling the `disabledProfileSources` setting, which is of the same type. - This feature does not change the behavior of `http`, `https` and `file` schemes. Validation I ran the dev terminal, and tested the behavior by clicking on `vscode` hyperlinks generated by ripgrep with various `safeUriSchemes` settings: - Setting not defined - asks for confirmation - `["vscode"]` - does not ask for confirmation - `["foo", "vscode"]` - does not ask for confirmation - `["foo"]` - asks for confirmation - `null` - asks for confirmation - `[]` - asks for confirmation - `[""]` - asks for confirmation - `[{"foo": "bar"}]` - fails to deserialize (as expected) A few uinit tests failed, but they seem unrelated to these changes: - `KeyBindingTests` in `UnitTests_SettingsModel`, probably because I use an AZERTY keyboard. - A few `Conhost` tests, but I didn't touch this part Refs #20065 Closes #20191 (cherry picked from commit fb71a04) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgshlaM Service-Version: 1.24
1 parent f86f4a2 commit b4e69c6

7 files changed

Lines changed: 34 additions & 4 deletions

File tree

doc/cascadia/profiles.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,13 @@
24622462
},
24632463
"type": "array"
24642464
},
2465+
"safeUriSchemes": {
2466+
"description": "Specifies a list of URI schemes that are considered safe. No confirmation will be required to open URIs with these schemes.",
2467+
"items": {
2468+
"type": "string"
2469+
},
2470+
"type": "array"
2471+
},
24652472
"rendering.graphicsAPI": {
24662473
"description": "Direct3D 11 provides a more performant and feature-rich experience, whereas Direct2D is more stable. The default option \"Automatic\" will pick the API that best fits your graphics hardware. If you experience significant issues, consider using Direct2D.",
24672474
"type": "string",

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,13 +3144,15 @@ namespace winrt::TerminalApp::implementation
31443144
return true;
31453145
}
31463146

3147-
bool TerminalPage::_IsUriConsideredSomewhatSafe(const winrt::Windows::Foundation::Uri& parsedUri)
3147+
bool TerminalPage::_IsUriConsideredSomewhatSafe(const winrt::Windows::Foundation::Uri& parsedUri) const
31483148
{
3149-
if (parsedUri.SchemeName() == L"http" || parsedUri.SchemeName() == L"https")
3149+
const auto& schemeName = parsedUri.SchemeName();
3150+
3151+
if (schemeName == L"http" || schemeName == L"https")
31503152
{
31513153
return true;
31523154
}
3153-
if (parsedUri.SchemeName() == L"file")
3155+
if (schemeName == L"file")
31543156
{
31553157
static const auto pathext{ wil::TryGetEnvironmentVariableW<std::wstring>(L"PATHEXT") };
31563158
const auto filename = parsedUri.Path();
@@ -3164,6 +3166,16 @@ namespace winrt::TerminalApp::implementation
31643166

31653167
return true;
31663168
}
3169+
if (const auto& safeSchemes = _settings.GlobalSettings().SafeUriSchemes())
3170+
{
3171+
for (const auto& scheme : safeSchemes)
3172+
{
3173+
if (til::equals_insensitive_ascii(schemeName, scheme))
3174+
{
3175+
return true;
3176+
}
3177+
}
3178+
}
31673179

31683180
return false;
31693181
}

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace winrt::TerminalApp::implementation
418418

419419
safe_void_coroutine _OpenHyperlinkHandler(const IInspectable sender, const Microsoft::Terminal::Control::OpenHyperlinkEventArgs eventArgs);
420420
static bool _IsUriSupported(const winrt::Windows::Foundation::Uri& parsedUri);
421-
static bool _IsUriConsideredSomewhatSafe(const winrt::Windows::Foundation::Uri& parsedUri);
421+
bool _IsUriConsideredSomewhatSafe(const winrt::Windows::Foundation::Uri& parsedUri) const;
422422

423423
void _ShowCouldNotOpenDialog(winrt::hstring reason, winrt::hstring uri);
424424
bool _CopyText(bool dismissSelection, bool singleLine, bool withControlSequences, Microsoft::Terminal::Control::CopyFormat formats);

src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
102102
globals->_DisabledProfileSources->Append(src);
103103
}
104104
}
105+
if (_SafeUriSchemes)
106+
{
107+
globals->_SafeUriSchemes = winrt::single_threaded_vector<hstring>();
108+
for (const auto& src : *_SafeUriSchemes)
109+
{
110+
globals->_SafeUriSchemes->Append(src);
111+
}
112+
}
105113

106114
for (const auto& parent : _parents)
107115
{

src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace Microsoft.Terminal.Settings.Model
105105
INHERITABLE_SETTING(Boolean, EnableUnfocusedAcrylic);
106106
INHERITABLE_SETTING(Boolean, AllowHeadless);
107107
INHERITABLE_SETTING(String, SearchWebDefaultQueryUrl);
108+
INHERITABLE_SETTING(IVector<String>, SafeUriSchemes);
108109

109110
Windows.Foundation.Collections.IMapView<String, ColorScheme> ColorSchemes();
110111
void AddColorScheme(ColorScheme scheme);

src/cascadia/TerminalSettingsModel/MTSMSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Author(s):
6262
X(bool, MinimizeToNotificationArea, "minimizeToNotificationArea", false) \
6363
X(bool, AlwaysShowNotificationIcon, "alwaysShowNotificationIcon", false) \
6464
X(winrt::Windows::Foundation::Collections::IVector<winrt::hstring>, DisabledProfileSources, "disabledProfileSources", nullptr) \
65+
X(winrt::Windows::Foundation::Collections::IVector<winrt::hstring>, SafeUriSchemes, "safeUriSchemes", nullptr) \
6566
X(bool, ShowAdminShield, "showAdminShield", true) \
6667
X(bool, TrimPaste, "trimPaste", true) \
6768
X(bool, EnableColorSelection, "experimental.enableColorSelection", false) \

src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ namespace SettingsModelUnitTests
461461
"$schema" : "https://aka.ms/terminal-profiles-schema",
462462
"defaultProfile": "{61c54bbd-1111-5271-96e7-009a87ff44bf}",
463463
"disabledProfileSources": [ "Windows.Terminal.Wsl" ],
464+
"safeUriSchemes": [ "vscode" ],
464465
"newTabMenu":
465466
[
466467
{

0 commit comments

Comments
 (0)