diff options
| author | Tino Calancha | 2018-02-15 09:09:50 +0900 |
|---|---|---|
| committer | Noam Postavsky | 2018-07-23 08:20:07 -0400 |
| commit | 2b70b54739a8a422aff85f0183fb69eb339c35d4 (patch) | |
| tree | 282c47615c71006d6173d4a6eb1043e43c0a9f9a | |
| parent | 5de444112cf19c078d4a74752a50e890233ef033 (diff) | |
| download | emacs-2b70b54739a8a422aff85f0183fb69eb339c35d4.tar.gz emacs-2b70b54739a8a422aff85f0183fb69eb339c35d4.zip | |
Prevent line-mode term from showing user passwords
For buffers whose mode derive from comint-mode, the user password is
read from the minibuffer and it's hidden. A buffer in term-mode and
line submode, instead shows the passwords. Make buffers in line
term-mode to hide passwords too (Bug#30190).
* lisp/term.el (term-send-invisible): Prefer the more robust
`read-passwd' instead of `term-read-noecho'.
(term-watch-for-password-prompt): New function.
(term-emulate-terminal): Call it each time we receive non-escape
sequence output.
Co-authored-by: Noam Postavsky <npostavs@gmail.com>
| -rw-r--r-- | lisp/term.el | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lisp/term.el b/lisp/term.el index b7f5b0e7f20..ae451e94bd6 100644 --- a/lisp/term.el +++ b/lisp/term.el | |||
| @@ -347,6 +347,7 @@ | |||
| 347 | (eval-when-compile (require 'cl-lib)) | 347 | (eval-when-compile (require 'cl-lib)) |
| 348 | (require 'ring) | 348 | (require 'ring) |
| 349 | (require 'ehelp) | 349 | (require 'ehelp) |
| 350 | (require 'comint) ; Password regexp. | ||
| 350 | 351 | ||
| 351 | (declare-function ring-empty-p "ring" (ring)) | 352 | (declare-function ring-empty-p "ring" (ring)) |
| 352 | (declare-function ring-ref "ring" (ring index)) | 353 | (declare-function ring-ref "ring" (ring index)) |
| @@ -2283,12 +2284,10 @@ applications." | |||
| 2283 | (defun term-send-invisible (str &optional proc) | 2284 | (defun term-send-invisible (str &optional proc) |
| 2284 | "Read a string without echoing. | 2285 | "Read a string without echoing. |
| 2285 | Then send it to the process running in the current buffer. A new-line | 2286 | Then send it to the process running in the current buffer. A new-line |
| 2286 | is additionally sent. String is not saved on term input history list. | 2287 | is additionally sent. String is not saved on term input history list." |
| 2287 | Security bug: your string can still be temporarily recovered with | ||
| 2288 | \\[view-lossage]." | ||
| 2289 | (interactive "P") ; Defeat snooping via C-x esc | 2288 | (interactive "P") ; Defeat snooping via C-x esc |
| 2290 | (when (not (stringp str)) | 2289 | (when (not (stringp str)) |
| 2291 | (setq str (term-read-noecho "Non-echoed text: " t))) | 2290 | (setq str (read-passwd "Non-echoed text: "))) |
| 2292 | (when (not proc) | 2291 | (when (not proc) |
| 2293 | (setq proc (get-buffer-process (current-buffer)))) | 2292 | (setq proc (get-buffer-process (current-buffer)))) |
| 2294 | (if (not proc) (error "Current buffer has no process") | 2293 | (if (not proc) (error "Current buffer has no process") |
| @@ -2297,6 +2296,16 @@ Security bug: your string can still be temporarily recovered with | |||
| 2297 | (term-send-string proc str) | 2296 | (term-send-string proc str) |
| 2298 | (term-send-string proc "\n"))) | 2297 | (term-send-string proc "\n"))) |
| 2299 | 2298 | ||
| 2299 | ;; TODO: Maybe combine this with `comint-watch-for-password-prompt'. | ||
| 2300 | (defun term-watch-for-password-prompt (string) | ||
| 2301 | "Prompt in the minibuffer for password and send without echoing. | ||
| 2302 | Checks if STRING contains a password prompt as defined by | ||
| 2303 | `comint-password-prompt-regexp'." | ||
| 2304 | (when (term-in-line-mode) | ||
| 2305 | (when (let ((case-fold-search t)) | ||
| 2306 | (string-match comint-password-prompt-regexp string)) | ||
| 2307 | (term-send-invisible (read-passwd string))))) | ||
| 2308 | |||
| 2300 | 2309 | ||
| 2301 | ;;; Low-level process communication | 2310 | ;;; Low-level process communication |
| 2302 | 2311 | ||
| @@ -3152,6 +3161,8 @@ See `term-prompt-regexp'." | |||
| 3152 | (term-handle-deferred-scroll)) | 3161 | (term-handle-deferred-scroll)) |
| 3153 | 3162 | ||
| 3154 | (set-marker (process-mark proc) (point)) | 3163 | (set-marker (process-mark proc) (point)) |
| 3164 | (when (stringp decoded-substring) | ||
| 3165 | (term-watch-for-password-prompt decoded-substring)) | ||
| 3155 | (when save-point | 3166 | (when save-point |
| 3156 | (goto-char save-point) | 3167 | (goto-char save-point) |
| 3157 | (set-marker save-point nil)) | 3168 | (set-marker save-point nil)) |