Skip to content

Commit 33556fb

Browse files
authored
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.
1 parent fb7b0e1 commit 33556fb

14 files changed

+38
-7
lines changed

doc/cascadia/profiles.schema.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -2373,11 +2373,6 @@
23732373
"description": "When set to true, Windows Terminal will run in the background. This allows globalSummon and quakeMode actions to work even when no windows are open.",
23742374
"type": "boolean"
23752375
},
2376-
"compatibility.allowDECRQCRA": {
2377-
"default": false,
2378-
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
2379-
"type": "boolean"
2380-
},
23812376
"compatibility.textMeasurement": {
23822377
"default": "graphemes",
23832378
"description": "This changes the way incoming text is grouped into cells. The \"graphemes\" option is the most modern and Unicode-correct way to do so, while \"wcswidth\" is a common approach on UNIX, and \"console\" replicates the way it used to work on Windows.",
@@ -2726,6 +2721,16 @@
27262721
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
27272722
"type": "boolean"
27282723
},
2724+
"compatibility.allowDECRQCRA": {
2725+
"default": false,
2726+
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
2727+
"type": "boolean"
2728+
},
2729+
"compatibility.allowOSC52": {
2730+
"default": true,
2731+
"description": "When set to true, VT applications will be allowed to set the contents of the local clipboard using OSC 52 (Manipulate Selection Data).",
2732+
"type": "boolean"
2733+
},
27292734
"unfocusedAppearance": {
27302735
"$ref": "#/$defs/AppearanceConfig",
27312736
"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
@@ -413,6 +413,7 @@ class Microsoft::Terminal::Core::Terminal final :
413413
Microsoft::Console::Types::Viewport _mutableViewport;
414414
til::CoordType _scrollbackLines = 0;
415415
bool _detectURLs = false;
416+
bool _clipboardOperationsAllowed = true;
416417

417418
til::size _altBufferSize;
418419
std::optional<til::size> _deferredResize;

src/cascadia/TerminalCore/TerminalApi.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ unsigned int Terminal::GetInputCodePage() const noexcept
140140

141141
void Terminal::CopyToClipboard(wil::zwstring_view content)
142142
{
143-
_pfnCopyToClipboard(content);
143+
if (_clipboardOperationsAllowed)
144+
{
145+
_pfnCopyToClipboard(content);
146+
}
144147
}
145148

146149
// Method Description:

src/cascadia/TerminalSettingsEditor/ProfileViewModel.h

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
154154
OBSERVABLE_PROJECTED_SETTING(_profile, RepositionCursorWithMouse);
155155
OBSERVABLE_PROJECTED_SETTING(_profile, ForceVTInput);
156156
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtChecksumReport);
157+
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtClipboardWrite);
157158
OBSERVABLE_PROJECTED_SETTING(_profile, AnswerbackMessage);
158159
OBSERVABLE_PROJECTED_SETTING(_profile, RainbowSuggestions);
159160
OBSERVABLE_PROJECTED_SETTING(_profile, PathTranslationStyle);

src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl

+1
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@ namespace Microsoft.Terminal.Settings.Editor
157157
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, AnswerbackMessage);
158158
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RainbowSuggestions);
159159
OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Control.PathTranslationStyle, PathTranslationStyle);
160+
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtClipboardWrite);
160161
}
161162
}

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
@@ -568,6 +568,10 @@
568568
<value>Allow DECRQCRA (Request Checksum of Rectangular Area)</value>
569569
<comment>{Locked="DECRQCRA"}{Locked="Request Checksum of Rectangular Area"}Header for a control to toggle support for the DECRQCRA control sequence.</comment>
570570
</data>
571+
<data name="Profile_AllowVtClipboardWrite.Header" xml:space="preserve">
572+
<value>Allow OSC 52 (Manipulate Selection Data) to write to the clipboard</value>
573+
<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>
574+
</data>
571575
<data name="Globals_AllowHeadless.Header" xml:space="preserve">
572576
<value>Allow Windows Terminal to run in the background</value>
573577
<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
@@ -101,6 +101,7 @@ Author(s):
101101
X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \
102102
X(bool, ForceVTInput, "compatibility.input.forceVT", false) \
103103
X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \
104+
X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \
104105
X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \
105106
X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None)
106107

src/cascadia/TerminalSettingsModel/Profile.idl

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ 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
INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.PathTranslationStyle, PathTranslationStyle);
99100
}

src/cascadia/TerminalSettingsModel/TerminalSettings.cpp

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

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)