Skip to content

Don't append is_password input to the PromptSession history - #2155

Open
neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:prompt-password-history
Open

neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:prompt-password-history

Conversation

@neeraj1235476

Copy link
Copy Markdown
Contributor

A PromptSession that reuses a FileHistory for a password prompt writes the password to the history file in plaintext:

session = PromptSession(history=FileHistory(path))
session.prompt("user: ")                         # alice
session.prompt("password: ", is_password=True)   # hunter2

$ cat history

# 2026-10-21 18:39:59.412506
+alice

# 2026-10-21 18:39:59.416079
+hunter2

The same entry can then be recalled with Up in a later non-password prompt, where it is shown unmasked. Buffer.validate_and_handle appends to the history unconditionally, so the default buffer now skips append_to_history while is_password is active. History navigation and non-password prompts are unchanged. A regression test is added in tests/test_cli.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant