terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Change "Open windows from a previous session" behavior to not automatically run .bat files without confirmation

Open rjk opened this issue 2 years ago • 2 comments

Description of the new feature/enhancement

Currently if you have the setting "Open windows from a previous session" on it will re-run .bat files that were executed in a previous session. e.g.

  • you double-click a .bat file to run it
  • you close the Terminal window
  • you later open Terminal e.g. from Start menu
  • Terminal will re-run that .bat file.

I think this is very surprising and potentially destructive behavior. Users would not expect that to happen or consider the potential disasters when enabling that setting.

I initially raised this as a bug in https://github.com/microsoft/terminal/issues/13151 which was closed as By Design, which is fine. This new issue is a suggestion to change the design.

Proposed technical implementation details

I think Terminal should do something else, e.g. one of these:

  • be more clever about what things it runs without user confirmation (e.g. perhaps it asks for user confirmation when running .bat and .cmd files on open, since they can be destructive. Or it simply never runs those types of files). I don't know enough about shells to know if this is easy/hard/impossible/annoying
  • give a big warning about this behavior on the setting page.
  • have two settings: one to persist tabs & working directories from previous sessions, one to persist potentially-destructive actions.

I don't think the setting page warning is sufficient, since many users will be blissfully unaware of all this. They might want tabs open from previous sessions, use that for months, and then just one time they use a .bat file for something. (Here, run this cleanup_files.bat but be careful not to run it with any unsaved changes). They open Terminal sometime later and BOOM the nasty .bat file has unexpectedly run. They lose their work, become sad, and end up hating Terminal forever :'(

rjk avatar Jun 15 '22 13:06 rjk

Sync meeting notes:

image

Add an option like... "Open windows from a previous session including defterm sessions" vs "Open windows from a previous session excluding defterm sessions" (this is the one that exists now)

carlos-zamora avatar Jul 25 '22 21:07 carlos-zamora

I started working on this in https://github.com/microsoft/terminal/compare/dev/lhecker/13151-defterm-persistence but I can't figure out how to properly handle split panes where both children are DefTerm sessions. The way Pane::BuildStartupActions works isn't particularly easy to modify for ad-hoc filtering like that. I'll try to pick this up next week again and finish it with the help of others.

lhecker avatar Aug 09 '22 23:08 lhecker

Oh, we may want to cross-reference with #13596 while we're here. Maybe this needs to be two separate sets of settings:

  • When Terminal starts
    • Open default profile
    • Open tabs from previous session, excluding defterm
    • Open tabs from previous session, including defterm
  • When Terminal starts as admin
    • Open default profile
    • Open tabs from previous session (no defterm settings here cause... well, you know, defterm doesn't work for elevated windows)

zadjii-msft avatar Aug 11 '22 15:08 zadjii-msft