Skip to content

Commit db7a50a

Browse files
committed
Let folks disable OSC 52 (#18449)
This pull request introduces a new profile setting, `compatibility.allowOSC52`, which defaults to `true`. When disabled, it will not allow applications to write to the clipboard. Security-minded folks may choose to disable it. (cherry picked from commit 33556fb) Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgWpodA Service-Version: 1.22
1 parent 6debbc3 commit db7a50a

14 files changed

+38
-7
lines changed

doc/cascadia/profiles.schema.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -2375,11 +2375,6 @@
23752375
"console"
23762376
]
23772377
},
2378-
"compatibility.allowDECRQCRA": {
2379-
"default": false,
2380-
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
2381-
"type": "boolean"
2382-
},
23832378
"copyFormatting": {
23842379
"default": true,
23852380
"description": "When set to `true`, the color and font formatting of selected text is also copied to your clipboard. When set to `false`, only plain text is copied to your clipboard. An array of specific formats can also be used. Supported array values include `html` and `rtf`. Plain text is always copied.",
@@ -2719,6 +2714,16 @@
27192714
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
27202715
"type": "boolean"
27212716
},
2717+
"compatibility.allowDECRQCRA": {
2718+
"default": false,
2719+
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
2720+
"type": "boolean"
2721+
},
2722+
"compatibility.allowOSC52": {
2723+
"default": true,
2724+
"description": "When set to true, VT applications will be allowed to set the contents of the local clipboard using OSC 52 (Manipulate Selection Data).",
2725+
"type": "boolean"
2726+
},
27222727
"unfocusedAppearance": {
27232728
"$ref": "#/$defs/AppearanceConfig",
27242729
"description": "Sets the appearance of the terminal when it is unfocused.",

src/cascadia/TerminalCore/ICoreSettings.idl

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.Terminal.Core
2222

2323
Boolean ForceVTInput;
2424
Boolean AllowVtChecksumReport;
25+
Boolean AllowVtClipboardWrite;
2526
Boolean TrimBlockSelection;
2627
Boolean DetectURLs;
2728

src/cascadia/TerminalCore/Terminal.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
8989
_trimBlockSelection = settings.TrimBlockSelection();
9090
_autoMarkPrompts = settings.AutoMarkPrompts();
9191
_rainbowSuggestions = settings.RainbowSuggestions();
92+
_clipboardOperationsAllowed = settings.AllowVtClipboardWrite();
9293

9394
if (_stateMachine)
9495
{

src/cascadia/TerminalCore/Terminal.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ class Microsoft::Terminal::Core::Terminal final :
409409
Microsoft::Console::Types::Viewport _mutableViewport;
410410
til::CoordType _scrollbackLines = 0;
411411
bool _detectURLs = false;
412+
bool _clipboardOperationsAllowed = true;
412413

413414
til::size _altBufferSize;
414415
std::optional<til::size> _deferredResize;

src/cascadia/TerminalCore/TerminalApi.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ unsigned int Terminal::GetConsoleOutputCP() const noexcept
116116

117117
void Terminal::CopyToClipboard(wil::zwstring_view content)
118118
{
119-
_pfnCopyToClipboard(content);
119+
if (_clipboardOperationsAllowed)
120+
{
121+
_pfnCopyToClipboard(content);
122+
}
120123
}
121124

122125
// Method Description:

src/cascadia/TerminalSettingsEditor/ProfileViewModel.h

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
122122
OBSERVABLE_PROJECTED_SETTING(_profile, RepositionCursorWithMouse);
123123
OBSERVABLE_PROJECTED_SETTING(_profile, ForceVTInput);
124124
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtChecksumReport);
125+
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtClipboardWrite);
125126
OBSERVABLE_PROJECTED_SETTING(_profile, AnswerbackMessage);
126127

127128
WINRT_PROPERTY(bool, IsBaseLayer, false);

src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl

+1
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ namespace Microsoft.Terminal.Settings.Editor
115115
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, ForceVTInput);
116116
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtChecksumReport);
117117
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, AnswerbackMessage);
118+
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtClipboardWrite);
118119
}
119120
}

src/cascadia/TerminalSettingsEditor/Profiles_Terminal.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@
6060
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
6161
</local:SettingContainer>
6262

63+
<!-- Allow VT Clipboard Writing -->
64+
<local:SettingContainer x:Uid="Profile_AllowVtClipboardWrite"
65+
ClearSettingValue="{x:Bind Profile.ClearAllowVtClipboardWrite}"
66+
HasSettingValue="{x:Bind Profile.HasAllowVtClipboardWrite, Mode=OneWay}"
67+
SettingOverrideSource="{x:Bind Profile.AllowVtClipboardWriteOverrideSource, Mode=OneWay}">
68+
<ToggleSwitch IsOn="{x:Bind Profile.AllowVtClipboardWrite, Mode=TwoWay}"
69+
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
70+
</local:SettingContainer>
71+
6372
<!-- Answerback Message -->
6473
<local:SettingContainer x:Uid="Profile_AnswerbackMessage"
6574
ClearSettingValue="{x:Bind Profile.ClearAnswerbackMessage}"

src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

+4
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@
560560
<value>Allow DECRQCRA (Request Checksum of Rectangular Area)</value>
561561
<comment>{Locked="DECRQCRA"}{Locked="Request Checksum of Rectangular Area"}Header for a control to toggle support for the DECRQCRA control sequence.</comment>
562562
</data>
563+
<data name="Profile_AllowVtClipboardWrite.Header" xml:space="preserve">
564+
<value>Allow OSC 52 (Manipulate Selection Data) to write to the clipboard</value>
565+
<comment>{Locked="OSC 52"}{Locked="Manipulate Selection Data"}Header for a control to toggle support for applications to change the contents of the Windows system clipboard.</comment>
566+
</data>
563567
<data name="Globals_AllowHeadless.Header" xml:space="preserve">
564568
<value>Allow Windows Terminal to run in the background</value>
565569
<comment>Header for a control to toggle support for Windows Terminal to run in the background.</comment>

src/cascadia/TerminalSettingsModel/MTSMSettings.h

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Author(s):
102102
X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \
103103
X(bool, ForceVTInput, "compatibility.input.forceVT", false) \
104104
X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \
105+
X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \
105106
X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false)
106107

107108
// Intentionally omitted Profile settings:

src/cascadia/TerminalSettingsModel/Profile.idl

+1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ namespace Microsoft.Terminal.Settings.Model
9494
INHERITABLE_PROFILE_SETTING(Boolean, ForceVTInput);
9595
INHERITABLE_PROFILE_SETTING(Boolean, AllowVtChecksumReport);
9696
INHERITABLE_PROFILE_SETTING(Boolean, AllowKeypadMode);
97+
INHERITABLE_PROFILE_SETTING(Boolean, AllowVtClipboardWrite);
9798
}
9899
}

src/cascadia/TerminalSettingsModel/TerminalSettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
349349
_RainbowSuggestions = profile.RainbowSuggestions();
350350
_ForceVTInput = profile.ForceVTInput();
351351
_AllowVtChecksumReport = profile.AllowVtChecksumReport();
352+
_AllowVtClipboardWrite = profile.AllowVtClipboardWrite();
352353
}
353354

354355
// Method Description:

src/cascadia/TerminalSettingsModel/TerminalSettings.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
9797
INHERITABLE_SETTING(Model::TerminalSettings, bool, AllowVtChecksumReport, false);
9898
INHERITABLE_SETTING(Model::TerminalSettings, bool, TrimBlockSelection, true);
9999
INHERITABLE_SETTING(Model::TerminalSettings, bool, DetectURLs, true);
100+
INHERITABLE_SETTING(Model::TerminalSettings, bool, AllowVtClipboardWrite, true);
100101

101102
INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference<Microsoft::Terminal::Core::Color>, TabColor, nullptr);
102103

src/cascadia/inc/ControlProperties.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
X(bool, AutoMarkPrompts) \
5353
X(bool, RepositionCursorWithMouse, false) \
5454
X(bool, RainbowSuggestions) \
55-
X(bool, AllowVtChecksumReport)
55+
X(bool, AllowVtChecksumReport) \
56+
X(bool, AllowVtClipboardWrite)
5657

5758
// --------------------------- Control Settings ---------------------------
5859
// All of these settings are defined in IControlSettings.

0 commit comments

Comments
 (0)