-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add settings to warn about large or multiline pastes #6631
Conversation
const bool hasNewLine = std::find(text.cbegin(), text.cend(), L'\n') != text.cend(); | ||
const bool warnMultiLine = hasNewLine && _settings->GlobalSettings().WarnAboutMultiLinePaste(); | ||
|
||
constexpr const std::size_t minimumSizeForWarning = 1024 * 5; // 5 KiB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put 5 KiB here for now, but I don't know what should be the optimal threshold for the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think five kilobytes is fine!
I haven't read any of the code and I already love it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My immediate concern is does there need to be a _RejectPasteButtonOnClick
that clears _acceptPaste
?
Yes, you're right, I will fix this. EDIT: Done. |
This is weird, I pushed a new commit on my branch (e4ccf28) but GitHub did not update the PR, and the CI did not run. Maybe someone at GitHub pasted a multi line command in a terminal accidentally and broke something... EDIT: I fixed it by squashing my two commits and force pushing. |
…haracter Before sending calling the `HandleClipboardData` member function on the `PasteFromClipboardEventArgs` object when we receive a request from the `TermControl` to send it the clipboard's text content, we now display a warning to let the user choose whether to continue or not if the text is larger than 5 KiB or contains the _new line_ character, which can be a security issue if the user is pasting the text in a shell. These warnings can be disabled with the `largePasteWarning` and `multiLinePasteWarning` global settings respectively. I merged `TerminalPage::_PasteFromClipboardHandler` and `TerminalPage::_PasteFromClipboardHandler` because I think that the code is simpler this way.
GETSET_PROPERTY(bool, WarnAboutLargePaste, true); | ||
GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be enabled by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was initially reluctant to enabled by default for both, but I've sat on it for a bit and I concur, enabled by default seems sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving. I just have a few discussion points but I don't think they should be blocking.
Should we display the text that's going to be pasted for reference?
| `largePasteWarning` | Optional | Boolean | `true` | When set to `true`, trying to paste text with more than 5 KiB of characters will display a warning asking you whether to continue or not with the paste. | | ||
| `multiLinePasteWarning` | Optional | Boolean | `true` | When set to `true`, trying to paste text with a _new line_ character will display a warning asking you whether to continue or not with the paste. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Discussion:
I'm wondering if we'll be adding more "warning" features over time. If so, what's everybody's thoughts on having a "warning." prefix? So these settings would be called warning.largePaste
and warning.multiLinePaste
.
And we could override some others like confirmCloseAllTabs
to be warning.closeWithMultipleTabs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wow, I actually like that a lot. I'd love another ACK on that design, but I'm on board.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll ACK that design. Should we do it in post so we can let greg904 in peace to merge his PR?
Making it a separate PR allows us to also add a compatibility lookup for warning.closeAllTabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I third this :)
GETSET_PROPERTY(bool, WarnAboutLargePaste, true); | ||
GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 😊
const bool hasNewLine = std::find(text.cbegin(), text.cend(), L'\n') != text.cend(); | ||
const bool warnMultiLine = hasNewLine && _settings->GlobalSettings().WarnAboutMultiLinePaste(); | ||
|
||
constexpr const std::size_t minimumSizeForWarning = 1024 * 5; // 5 KiB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think five kilobytes is fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'm cool with this. I won't block on the resume_foreground
thing, I trust it'll get sorted out before Dustin signs off
<value>Cancel</value> | ||
</data> | ||
<data name="LargePasteDialog.Content" xml:space="preserve"> | ||
<value>You are about to paste text that is longer than 5 KiB. This can make the terminal unresponsive while the text is being received on the other end. Are you sure you want to continue?</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
<value>You are about to paste text that is longer than 5 KiB. This can make the terminal unresponsive while the text is being received on the other end. Are you sure you want to continue?</value> | |
<value>You are about to paste text that is longer than 5 KiB. Are you sure you want to continue?</value> |
@cinnamon-msft for confirmation on the wording here though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zadjii-msft's wording looks great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay actually, can we change "Are you sure you want to continue?" to "Do you wish to continue?" to match the other message?
<value>Cancel</value> | ||
</data> | ||
<data name="MultiLinePasteDialog.Content" xml:space="preserve"> | ||
<value>You are about to paste text that contains the "new line" character. If you paste text that contains the "new line" character into a shell, one or more command(s) will be executed automatically upon paste. Are you sure you want to continue?</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
<value>You are about to paste text that contains the "new line" character. If you paste text that contains the "new line" character into a shell, one or more command(s) will be executed automatically upon paste. Are you sure you want to continue?</value> | |
<value>You are about to paste text that contains the "new line" character. If you paste text that contains the "new line" character into a shell, one or more command(s) might be executed automatically upon paste. Are you sure you want to continue?</value> |
again, @cinnamon-msft to ACK this wording
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might rephrase as "You are about to paste text that contains multiple lines. If you paste this text into your shell, it may result in the unexpected execution of commands. Are you sure you want to continue?"
edit: "are you sure you wish to continue?" ("wish" stuck with me a bit more than "want")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my go at wordsmithing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like:
You are about to paste text that contains multiple lines. If you paste this text into your shell, it may result in the unexpected execution of commands. Do you wish to continue?
We also need a PR in the docs repo (or at the very least an issue please). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I LOVE THIS SO MUCH
THANK YOU
Just minor nits. I'll let my red-x from before ride, but I'd like to have out the discussion about the coroutine returns
<value>Cancel</value> | ||
</data> | ||
<data name="MultiLinePasteDialog.Content" xml:space="preserve"> | ||
<value>You are about to paste text that contains the "new line" character. If you paste text that contains the "new line" character into a shell, one or more command(s) will be executed automatically upon paste. Are you sure you want to continue?</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might rephrase as "You are about to paste text that contains multiple lines. If you paste this text into your shell, it may result in the unexpected execution of commands. Are you sure you want to continue?"
edit: "are you sure you wish to continue?" ("wish" stuck with me a bit more than "want")
<value>Cancel</value> | ||
</data> | ||
<data name="MultiLinePasteDialog.Content" xml:space="preserve"> | ||
<value>You are about to paste text that contains the "new line" character. If you paste text that contains the "new line" character into a shell, one or more command(s) will be executed automatically upon paste. Are you sure you want to continue?</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my go at wordsmithing
Paging @cinnamon-msft We need you in this PR to handle some dialog wording. |
I absolutely love this! Next maybe warn users about pasting binary text into the terminal? I think I’ve seen this in some terminals. Xfce Terminal warns me every time when I paste something with “sudo” command. That’s also kinda sweet but I don’t think we should go that far. |
EDIT: Fixed. |
Hello @DHowett! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this. :)
🎉 Handy links: |
Before sending calling the
HandleClipboardData
member function onthe
PasteFromClipboardEventArgs
object when we receive a requestfrom the
TermControl
to send it the clipboard's text content, wenow display a warning to let the user choose whether to continue or
not if the text is larger than 5 KiB or contains the new line
character, which can be a security issue if the user is pasting the
text in a shell.
These warnings can be disabled with the
largePasteWarning
andmultiLinePasteWarning
global settings respectively.Closes #2349