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.
This commit is contained in:
Dustin L. Howett
2025-01-23 18:28:02 -06:00
committed by GitHub
parent fb7b0e1218
commit 33556fb631
14 changed files with 38 additions and 7 deletions

View File

@@ -2373,11 +2373,6 @@
"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.",
"type": "boolean"
},
"compatibility.allowDECRQCRA": {
"default": false,
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
"type": "boolean"
},
"compatibility.textMeasurement": {
"default": "graphemes",
"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 @@
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
"type": "boolean"
},
"compatibility.allowDECRQCRA": {
"default": false,
"description": "When set to true, the terminal will support the DECRQCRA (Request Checksum of Rectangular Area) escape sequence.",
"type": "boolean"
},
"compatibility.allowOSC52": {
"default": true,
"description": "When set to true, VT applications will be allowed to set the contents of the local clipboard using OSC 52 (Manipulate Selection Data).",
"type": "boolean"
},
"unfocusedAppearance": {
"$ref": "#/$defs/AppearanceConfig",
"description": "Sets the appearance of the terminal when it is unfocused.",

View File

@@ -22,6 +22,7 @@ namespace Microsoft.Terminal.Core
Boolean ForceVTInput;
Boolean AllowVtChecksumReport;
Boolean AllowVtClipboardWrite;
Boolean TrimBlockSelection;
Boolean DetectURLs;

View File

@@ -89,6 +89,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
_trimBlockSelection = settings.TrimBlockSelection();
_autoMarkPrompts = settings.AutoMarkPrompts();
_rainbowSuggestions = settings.RainbowSuggestions();
_clipboardOperationsAllowed = settings.AllowVtClipboardWrite();
if (_stateMachine)
{

View File

@@ -413,6 +413,7 @@ private:
Microsoft::Console::Types::Viewport _mutableViewport;
til::CoordType _scrollbackLines = 0;
bool _detectURLs = false;
bool _clipboardOperationsAllowed = true;
til::size _altBufferSize;
std::optional<til::size> _deferredResize;

View File

@@ -140,7 +140,10 @@ unsigned int Terminal::GetInputCodePage() const noexcept
void Terminal::CopyToClipboard(wil::zwstring_view content)
{
_pfnCopyToClipboard(content);
if (_clipboardOperationsAllowed)
{
_pfnCopyToClipboard(content);
}
}
// Method Description:

View File

@@ -154,6 +154,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_profile, RepositionCursorWithMouse);
OBSERVABLE_PROJECTED_SETTING(_profile, ForceVTInput);
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtChecksumReport);
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtClipboardWrite);
OBSERVABLE_PROJECTED_SETTING(_profile, AnswerbackMessage);
OBSERVABLE_PROJECTED_SETTING(_profile, RainbowSuggestions);
OBSERVABLE_PROJECTED_SETTING(_profile, PathTranslationStyle);

View File

@@ -157,5 +157,6 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, AnswerbackMessage);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RainbowSuggestions);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Control.PathTranslationStyle, PathTranslationStyle);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtClipboardWrite);
}
}

View File

@@ -60,6 +60,15 @@
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Allow VT Clipboard Writing -->
<local:SettingContainer x:Uid="Profile_AllowVtClipboardWrite"
ClearSettingValue="{x:Bind Profile.ClearAllowVtClipboardWrite}"
HasSettingValue="{x:Bind Profile.HasAllowVtClipboardWrite, Mode=OneWay}"
SettingOverrideSource="{x:Bind Profile.AllowVtClipboardWriteOverrideSource, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind Profile.AllowVtClipboardWrite, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Answerback Message -->
<local:SettingContainer x:Uid="Profile_AnswerbackMessage"
ClearSettingValue="{x:Bind Profile.ClearAnswerbackMessage}"

View File

@@ -568,6 +568,10 @@
<value>Allow DECRQCRA (Request Checksum of Rectangular Area)</value>
<comment>{Locked="DECRQCRA"}{Locked="Request Checksum of Rectangular Area"}Header for a control to toggle support for the DECRQCRA control sequence.</comment>
</data>
<data name="Profile_AllowVtClipboardWrite.Header" xml:space="preserve">
<value>Allow OSC 52 (Manipulate Selection Data) to write to the clipboard</value>
<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>
</data>
<data name="Globals_AllowHeadless.Header" xml:space="preserve">
<value>Allow Windows Terminal to run in the background</value>
<comment>Header for a control to toggle support for Windows Terminal to run in the background.</comment>

View File

@@ -101,6 +101,7 @@ Author(s):
X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \
X(bool, ForceVTInput, "compatibility.input.forceVT", false) \
X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \
X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \
X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \
X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None)

View File

@@ -94,6 +94,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_PROFILE_SETTING(Boolean, ForceVTInput);
INHERITABLE_PROFILE_SETTING(Boolean, AllowVtChecksumReport);
INHERITABLE_PROFILE_SETTING(Boolean, AllowKeypadMode);
INHERITABLE_PROFILE_SETTING(Boolean, AllowVtClipboardWrite);
INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.PathTranslationStyle, PathTranslationStyle);
}

View File

@@ -348,6 +348,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_RainbowSuggestions = profile.RainbowSuggestions();
_ForceVTInput = profile.ForceVTInput();
_AllowVtChecksumReport = profile.AllowVtChecksumReport();
_AllowVtClipboardWrite = profile.AllowVtClipboardWrite();
_PathTranslationStyle = profile.PathTranslationStyle();
}

View File

@@ -97,6 +97,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, bool, AllowVtChecksumReport, false);
INHERITABLE_SETTING(Model::TerminalSettings, bool, TrimBlockSelection, true);
INHERITABLE_SETTING(Model::TerminalSettings, bool, DetectURLs, true);
INHERITABLE_SETTING(Model::TerminalSettings, bool, AllowVtClipboardWrite, true);
INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference<Microsoft::Terminal::Core::Color>, TabColor, nullptr);

View File

@@ -52,7 +52,8 @@
X(bool, AutoMarkPrompts) \
X(bool, RepositionCursorWithMouse, false) \
X(bool, RainbowSuggestions) \
X(bool, AllowVtChecksumReport)
X(bool, AllowVtChecksumReport) \
X(bool, AllowVtClipboardWrite)
// --------------------------- Control Settings ---------------------------
// All of these settings are defined in IControlSettings.