How can I hide sensitive information like passwords from python program output logs?
I wonder if there is a python module that I can use as a filter for stdout for preventing to display sensitive information like passwords or credentials?
I am looking for a generic solution as I have no control or prior knowledge of what is effectively printed (is output of user defined shell commands). Still, as a safety measure I would prefer to hide information that is likely to be sensistive.
Real life example: "set" prints environment variable and would clearly expose OS_PASSWORD if defined. If the filter I am describing would just replace the value with * it would make it safe to use.
I tried to search on https://pypi.org but I wasnt able to find anything, yet.
We can assume that python logging is used for output as that is the recommanded way to log anything in python.
Clarification: there is no way for me to know which environment variables may need to be sanitized, by default the tool does not need any credentials so I need a generic solution that has a default set of known to be sensitiv.
The same kind of problem is faced on any CI system that is public that that needs some credentials in order to function. A decent approach is to sanitize the output to avoid accidental leakage of information. For example an user may add a "set" that would expose some of these variables to the logs.
This is not about malicious usses that may easily find a way to bypass a filtering system if they really want, is more about preventing accidental leakage caused by code that you cannot control.
So unsafe code needs access to sensitive information and you cannot prevent it from displaying it. All I am looking for is for some "white-paste" solution....
python security logging
add a comment |
I wonder if there is a python module that I can use as a filter for stdout for preventing to display sensitive information like passwords or credentials?
I am looking for a generic solution as I have no control or prior knowledge of what is effectively printed (is output of user defined shell commands). Still, as a safety measure I would prefer to hide information that is likely to be sensistive.
Real life example: "set" prints environment variable and would clearly expose OS_PASSWORD if defined. If the filter I am describing would just replace the value with * it would make it safe to use.
I tried to search on https://pypi.org but I wasnt able to find anything, yet.
We can assume that python logging is used for output as that is the recommanded way to log anything in python.
Clarification: there is no way for me to know which environment variables may need to be sanitized, by default the tool does not need any credentials so I need a generic solution that has a default set of known to be sensitiv.
The same kind of problem is faced on any CI system that is public that that needs some credentials in order to function. A decent approach is to sanitize the output to avoid accidental leakage of information. For example an user may add a "set" that would expose some of these variables to the logs.
This is not about malicious usses that may easily find a way to bypass a filtering system if they really want, is more about preventing accidental leakage caused by code that you cannot control.
So unsafe code needs access to sensitive information and you cannot prevent it from displaying it. All I am looking for is for some "white-paste" solution....
python security logging
2
I'm a bit confused. If you, the developer, have"no .. prior knowledge of what is effectively printed"than how would a theoretically-existing module know? How would it know thatsuper_sensitive_passwordis going to be logged?
– DeepSpace
Nov 13 '18 at 11:32
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, therootuser (or any user with unlimitedsudoprivileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.
– Daniel Pryden
Nov 13 '18 at 12:47
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51
add a comment |
I wonder if there is a python module that I can use as a filter for stdout for preventing to display sensitive information like passwords or credentials?
I am looking for a generic solution as I have no control or prior knowledge of what is effectively printed (is output of user defined shell commands). Still, as a safety measure I would prefer to hide information that is likely to be sensistive.
Real life example: "set" prints environment variable and would clearly expose OS_PASSWORD if defined. If the filter I am describing would just replace the value with * it would make it safe to use.
I tried to search on https://pypi.org but I wasnt able to find anything, yet.
We can assume that python logging is used for output as that is the recommanded way to log anything in python.
Clarification: there is no way for me to know which environment variables may need to be sanitized, by default the tool does not need any credentials so I need a generic solution that has a default set of known to be sensitiv.
The same kind of problem is faced on any CI system that is public that that needs some credentials in order to function. A decent approach is to sanitize the output to avoid accidental leakage of information. For example an user may add a "set" that would expose some of these variables to the logs.
This is not about malicious usses that may easily find a way to bypass a filtering system if they really want, is more about preventing accidental leakage caused by code that you cannot control.
So unsafe code needs access to sensitive information and you cannot prevent it from displaying it. All I am looking for is for some "white-paste" solution....
python security logging
I wonder if there is a python module that I can use as a filter for stdout for preventing to display sensitive information like passwords or credentials?
I am looking for a generic solution as I have no control or prior knowledge of what is effectively printed (is output of user defined shell commands). Still, as a safety measure I would prefer to hide information that is likely to be sensistive.
Real life example: "set" prints environment variable and would clearly expose OS_PASSWORD if defined. If the filter I am describing would just replace the value with * it would make it safe to use.
I tried to search on https://pypi.org but I wasnt able to find anything, yet.
We can assume that python logging is used for output as that is the recommanded way to log anything in python.
Clarification: there is no way for me to know which environment variables may need to be sanitized, by default the tool does not need any credentials so I need a generic solution that has a default set of known to be sensitiv.
The same kind of problem is faced on any CI system that is public that that needs some credentials in order to function. A decent approach is to sanitize the output to avoid accidental leakage of information. For example an user may add a "set" that would expose some of these variables to the logs.
This is not about malicious usses that may easily find a way to bypass a filtering system if they really want, is more about preventing accidental leakage caused by code that you cannot control.
So unsafe code needs access to sensitive information and you cannot prevent it from displaying it. All I am looking for is for some "white-paste" solution....
python security logging
python security logging
edited Nov 17 '18 at 16:07
sorin
asked Nov 13 '18 at 11:28
sorinsorin
75k116370579
75k116370579
2
I'm a bit confused. If you, the developer, have"no .. prior knowledge of what is effectively printed"than how would a theoretically-existing module know? How would it know thatsuper_sensitive_passwordis going to be logged?
– DeepSpace
Nov 13 '18 at 11:32
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, therootuser (or any user with unlimitedsudoprivileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.
– Daniel Pryden
Nov 13 '18 at 12:47
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51
add a comment |
2
I'm a bit confused. If you, the developer, have"no .. prior knowledge of what is effectively printed"than how would a theoretically-existing module know? How would it know thatsuper_sensitive_passwordis going to be logged?
– DeepSpace
Nov 13 '18 at 11:32
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, therootuser (or any user with unlimitedsudoprivileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.
– Daniel Pryden
Nov 13 '18 at 12:47
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51
2
2
I'm a bit confused. If you, the developer, have
"no .. prior knowledge of what is effectively printed" than how would a theoretically-existing module know? How would it know that super_sensitive_password is going to be logged?– DeepSpace
Nov 13 '18 at 11:32
I'm a bit confused. If you, the developer, have
"no .. prior knowledge of what is effectively printed" than how would a theoretically-existing module know? How would it know that super_sensitive_password is going to be logged?– DeepSpace
Nov 13 '18 at 11:32
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, the
root user (or any user with unlimited sudo privileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.– Daniel Pryden
Nov 13 '18 at 12:47
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, the
root user (or any user with unlimited sudo privileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.– Daniel Pryden
Nov 13 '18 at 12:47
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51
add a comment |
1 Answer
1
active
oldest
votes
Try hashing it by using the sha-256 algorithm
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280058%2fhow-can-i-hide-sensitive-information-like-passwords-from-python-program-output-l%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try hashing it by using the sha-256 algorithm
add a comment |
Try hashing it by using the sha-256 algorithm
add a comment |
Try hashing it by using the sha-256 algorithm
Try hashing it by using the sha-256 algorithm
answered Nov 13 '18 at 14:00
user8221260user8221260
305
305
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280058%2fhow-can-i-hide-sensitive-information-like-passwords-from-python-program-output-l%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I'm a bit confused. If you, the developer, have
"no .. prior knowledge of what is effectively printed"than how would a theoretically-existing module know? How would it know thatsuper_sensitive_passwordis going to be logged?– DeepSpace
Nov 13 '18 at 11:32
This sounds like a symptom of a deeper problem. If you're passing credentials on the command line, be aware that on most Linux systems, any user on the box, even unprivileged users, can easily see the complete command line of every command executed. Additionally, the
rootuser (or any user with unlimitedsudoprivileges) can easily inspect the environment variables of any process. Before trying to mitigate a threat, you need to understand what the threat is that you're trying to defend against.– Daniel Pryden
Nov 13 '18 at 12:47
You have two ways to solve this problem. Either (1) figure out a way to ensure that credentials are never put into logs, or (2) assume all logs contain credentials, and lock them down so only administrators are allowed to read them. Most likely, you will want to do both.
– Daniel Pryden
Nov 13 '18 at 12:51