Skip to content

Commit

Permalink
Clear web terminal when session ends (#8850)
Browse files Browse the repository at this point in the history
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web.

Co-authored-by: Grzegorz <[email protected]>
Co-authored-by: Russell Jones <[email protected]>
  • Loading branch information
3 people committed Dec 15, 2021
1 parent a341730 commit f699ebb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func newSession(client *NodeClient,
defer ns.closeWait.Done()

<-ns.closer.C
if isFIPS() {
if err := ns.terminal.Clear(); err != nil {
log.Warnf("Failed to clear screen: %v.", err)
}
}
ns.terminal.Close()
}()

Expand Down
12 changes: 12 additions & 0 deletions lib/client/terminal/terminal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ func (e *signalEmitter) clearSubscribers() {
}
e.subscribers = e.subscribers[:0]
}

// Clear clears the terminal, including scrollback.
func (t *Terminal) Clear() error {
// \x1b[3J - clears scrollback (it is needed at least for the Mac terminal) -
// https://newbedev.com/how-do-i-reset-the-scrollback-in-the-terminal-via-a-shell-command
// \x1b\x63 - clears current screen - same as '\0033\0143' from https://superuser.com/a/123007
const resetPattern = "\x1b[3J\x1b\x63\n"
if _, err := t.Stdout().Write([]byte(resetPattern)); err != nil {
return trace.Wrap(err)
}
return nil
}

0 comments on commit f699ebb

Please sign in to comment.