prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Passwords are not correctly hidden, contrary to getpass.getpass()

Open
#1,888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Hello,

I don't know how prompt_toolkit tries to hide passwords, but it looks
like passwords are not correctly hidden. In particular, using Emacs I
can see that contrary to getpass.getpass() the password is not
correctly hidden. I don't know what getpass() does that
prompt_toolkit does not though.

Emacs can be used to reveal the problem.

To reproduce the problem:

Start a shell within Emacs:

$ emacs -Q --eval "(shell)"

Within the shell within Emacs, try getpass(), entering "abc" as
password:

$ python3 -c "import getpass; getpass.getpass(\"Password: \")"
Password: 
$

As you can see, the password is not displayed.

And try using prompt_toolkit, entering "abc" as password:

$ python3 -c "import prompt_toolkit; prompt_toolkit.prompt(\"Password: \", is_password=True)"
Password: abc
$

As you can see, contrary to getpass(), the password is shown.

Does prompt_toolkit have issues setting the terminal in noecho mode?

Does prompt_toolkit really display the password characters and then
tries to replace them very quickly, contrary to getpass() which
effectively hides the password?

Is there something else not properly set up in prompt_toolkit compared
to getpass()?

Note: to exit Emacs, do: control-x control-c and watch for any prompts at the bottom left of the screen.

Thanks!

Best regards
Fabrice

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Emacs shell commands, comparing Python getpass.getpass() with prompt_toolkit.prompt(..., is_password=True). Trace the password-prompt and terminal echo handling; done means entered password characters remain hidden in the Emacs shell as they do with getpass().

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.