Bracketed paste mode probably shouldn't disable the multiline paste warning #17375

Closed
opened 2026-01-31 05:40:35 +00:00 by claunia · 7 comments
Owner

Originally created by @j4james on GitHub (May 1, 2022).

Windows Terminal version

1.13.10336.0

Windows build number

10.0.19041.1415

Other Software

No response

Steps to reproduce

  1. Make sure the multilinePasteWarning setting is enabled.
  2. Open pwsh in Windows Terminal tab.
  3. Execute the following command: echo "`e[?2004h`e]52;;ZGlyCnJlbQo=`e\"
  4. Right click in the terminal window (NB: this is going to execute a dir command without prompting - it could just as easily be something more malicious).

Expected Behavior

I'd expect the terminal should warn me before pasting and executing multiline commands.

Actual Behavior

The terminal pastes the multiline command without any confirmation and the shell immediately executes it.

Basically we've got a security feature (the multiline paste warning), which can be trivially disabled with an escaped sequence (bracketed paste mode). This might be OK if we could assume all shells supported bracketed paste mode, and wouldn't execute commands when wrapped in a bracketed escape sequence, but that's not the case for PowerShell or the cmd shell.

I realise this behavior was added intentionally (see #7006 and PR #9586), but in retrospect I think that was a mistake. The multiline paste warning is giving an illusion of safety which now can't be relied on.

Originally created by @j4james on GitHub (May 1, 2022). ### Windows Terminal version 1.13.10336.0 ### Windows build number 10.0.19041.1415 ### Other Software _No response_ ### Steps to reproduce 1. Make sure the [`multilinePasteWarning`](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/interaction#warn-when-the-text-to-paste-contains-multiple-lines) setting is enabled. 2. Open `pwsh` in Windows Terminal tab. 3. Execute the following command: ```echo "`e[?2004h`e]52;;ZGlyCnJlbQo=`e\"``` 4. Right click in the terminal window (NB: this is going to execute a `dir` command without prompting - it could just as easily be something more malicious). ### Expected Behavior I'd expect the terminal should warn me before pasting and executing multiline commands. ### Actual Behavior The terminal pastes the multiline command without any confirmation and the shell immediately executes it. Basically we've got a security feature (the multiline paste warning), which can be trivially disabled with an escaped sequence (bracketed paste mode). This might be OK if we could assume all shells supported bracketed paste mode, and wouldn't execute commands when wrapped in a bracketed escape sequence, but that's not the case for PowerShell or the cmd shell. I realise this behavior was added intentionally (see #7006 and PR #9586), but in retrospect I think that was a mistake. The multiline paste warning is giving an illusion of safety which now can't be relied on.
Author
Owner

@DHowett commented on GitHub (May 1, 2022):

I'm mobile and doing a "drive-by," but my first thought is that to get bracketed paste mode enabled in a shell that doesn't request it by default, the attacker would need to first get the user to do something, and something somewhat unnatural at that. Now, if there's a shell in the wild that requests it but cannot handle it, that will be a problem...

@DHowett commented on GitHub (May 1, 2022): I'm mobile and doing a "drive-by," but my first thought is that to get bracketed paste mode enabled in a shell that *doesn't* request it by default, the attacker would need to first get the user to do something, and something somewhat unnatural at that. Now, if there's a shell in the wild that requests it but cannot handle it, that will be a problem...
Author
Owner

@j4james commented on GitHub (May 2, 2022):

Check out this game of minesweeper that you can play in the terminal - just telnet to minesweeper.evil.example.com. Game instructions: Left click on a cell to open it; right click to flag it.

Except this "game" has enabled bracketed paste mode and copied its attack script to the clipboard. And when you right click, it doesn't capture the mouse, but allows the click to be handled by the terminal as a paste operation. The first characters that are received will cause the app to terminate, and the rest get passed on to the shell.

Now that I think about it, that should even work in a shell that supports bracketed paste, because the app could eat the opening bracket sequence.

I haven't actually tried, so maybe there's something I'm missing that would prevent an attack like that from working, but it could also be something unintentional like an editor crashing while in bracketed paste mode. If you're billing the multiline paste warning as a safety net that can prevent unintentional execution, it really shouldn't be possible for an app to turn that off (IMO).

@j4james commented on GitHub (May 2, 2022): Check out this game of minesweeper that you can play in the terminal - just telnet to minesweeper.evil.example.com. Game instructions: Left click on a cell to open it; right click to flag it. Except this "game" has enabled bracketed paste mode and copied its attack script to the clipboard. And when you right click, it doesn't capture the mouse, but allows the click to be handled by the terminal as a paste operation. The first characters that are received will cause the app to terminate, and the rest get passed on to the shell. Now that I think about it, that should even work in a shell that supports bracketed paste, because the app could eat the opening bracket sequence. I haven't actually tried, so maybe there's something I'm missing that would prevent an attack like that from working, but it could also be something unintentional like an editor crashing while in bracketed paste mode. If you're billing the multiline paste warning as a safety net that can prevent unintentional execution, it really shouldn't be possible for an app to turn that off (IMO).
Author
Owner

@j4james commented on GitHub (May 2, 2022):

That said, it's OK if you want to just close this as working-as-designed, and users just need to be aware that they shouldn't use Windows Terminal in an untrusted environment, or be careful of what they click on.

If that's the case, though, I'd probably open a feature request for something like a "safe-mode" setting, which would disable potentially risky ops like OSC 52. That could also then allow us to add other operations that we've previously avoided due to security concerns.

@j4james commented on GitHub (May 2, 2022): That said, it's OK if you want to just close this as working-as-designed, and users just need to be aware that they shouldn't use Windows Terminal in an untrusted environment, or be careful of what they click on. If that's the case, though, I'd probably open a feature request for something like a "safe-mode" setting, which would disable potentially risky ops like `OSC 52`. That could also then allow us to add other operations that we've previously avoided due to security concerns.
Author
Owner

@DHowett commented on GitHub (Apr 26, 2023):

I'm gonna mark this one up for team discussion, as I gave you a drive-by and didn't ever circle back on it.

@DHowett commented on GitHub (Apr 26, 2023): I'm gonna mark this one up for team discussion, as I gave you a drive-by and didn't ever circle back on it.
Author
Owner

@lhecker commented on GitHub (May 8, 2023):

What if we suppress the warning only if bracketed paste and mouse mode is enabled? That way you could still use vim comfortably, but it would be safe elsewhere and show a warning.

@lhecker commented on GitHub (May 8, 2023): What if we suppress the warning only if bracketed paste _and_ mouse mode is enabled? That way you could still use vim comfortably, but it would be safe elsewhere and show a warning.
Author
Owner

@j4james commented on GitHub (May 9, 2023):

@lhecker That sounds like a reasonable solution from my point of view. But it may be worth asking the people in #7006 whether it still meets their needs, since they were the ones that wanted the warning removed in the first place.

I'd also be happy with having the multiLinePasteWarning option extended to support more choices, e.g. always, never, and whatever your want to call the inbetween mode. I don't know if that's overcomplicating things though.

@j4james commented on GitHub (May 9, 2023): @lhecker That sounds like a reasonable solution from my point of view. But it may be worth asking the people in #7006 whether it still meets their needs, since they were the ones that wanted the warning removed in the first place. I'd also be happy with having the `multiLinePasteWarning` option extended to support more choices, e.g. `always`, `never`, and whatever your want to call the inbetween mode. I don't know if that's overcomplicating things though.
Author
Owner

@lhecker commented on GitHub (Jul 28, 2025):

I'm not entirely sure what I thought when I suggested using the mouse mode as a heuristic... An attacker could enable mouse mode and pwsh would still gobble up the bracketed paste.

@lhecker commented on GitHub (Jul 28, 2025): I'm not entirely sure what I thought when I suggested using the mouse mode as a heuristic... An attacker could enable mouse mode and pwsh would still gobble up the bracketed paste.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17375