Using os code is generally accepted as bad practice from a security perspective, as it could potentially provide a bad actor with phenomenal cosmic powers. Nonetheless, most sources appear to recommend using the following to get env variables.
import os
print(os.environ['FOO'])
This approach is also suggested here on SO, such as in "How to access environment variable values?" I know that one can use dotenv to pick up a .env file and to create new env variables, but I have not been able to find anything for existing env variables.
This leads me to the following questions.
- Is Python's
ossecure enough to render my concerns unnecessary? - Is
from os import environany better than going for the entireimport os? - Is there a method that is more secure and avoids
osentirely?
Thanks muchley!
osthat may be risky (such as theos.execfamily) if you don't use them properly. But environment variables are no more risky that user input.osspecifically is bad, I was saying that, in general, it is advised to avoid using operating system code for security reasons. Whether this extends to Python'sosis the aim of this question.osmodule isn't operating system code. It's Python code. It has that name because it provides access to facilities that are provided by the operating system or the shell. You are reading way too much into the way it is named.