securely passing a password to subprocess.Popen via environment

亡梦爱人 提交于 2019-12-23 12:53:55

问题


I would like to securely ask a password to a user and then pass it to subprocess.Popen to run a command that requires it.

I have seen this question and that one, but I wonder if I can securely pass the password via the subprocess environment like that:

import subprocess, os
user_password = input("what is you password?")
my_env = os.environ.copy()
my_env["userpass"] = user_password
my_command = "python --version"
subprocess.Popen(my_command, env=my_env)

Will the password be flushed once the python script is closed ? I have look at the subprocess documentation but it's not explained.

When I add this line print(os.environ['userpass']) at the end of my code to print the OS environment, I can retrieve the user password. Do it means that the password can be access by the other running processes ?

Edit: I can't pipe the password as the command I use doesn't read its password from standard input

来源:https://stackoverflow.com/questions/53232728/securely-passing-a-password-to-subprocess-popen-via-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!