File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,13 @@ def spider_closed(self, spider):
5353 settings = {k : v for k , v in settings .items () if re .search (regex , k )}
5454 if settings .get ("MASKED_SENSITIVE_SETTINGS_ENABLED" , True ):
5555 default_regexes = [
56- "(?i)(api[\W_]*key)" , # apikey and possible variations
57- "(?i)(AWS[\W_]*SECRET[\W_]*ACCESS[\W_]*KEY)" # AWS_SECRET_ACCESS_KEY and possible variations
56+ ".*(?i)(api[\W_]*key).*" , # apikey and possible variations e.g: shub_apikey or SC_APIKEY
57+ ".*(?i)(AWS[\W_]*SECRET[\W_]*ACCESS[\W_]*KEY).*" , # AWS_SECRET_ACCESS_KEY and possible variations
58+ ".*(?i)([\W_]*password[\W_]*).*" # password word
5859 ]
5960 regex_list = settings .get ("MASKED_SENSITIVE_SETTINGS_REGEX_LIST" , default_regexes )
6061 for reg in regex_list :
61- updated_settings = {k : '*' * len (v ) for k , v in settings .items () if re .search (reg , k )}
62+ updated_settings = {k : '*' * len (v ) if v else v for k , v in settings .items () if re .match (reg , k )}
6263 settings = {** settings , ** updated_settings }
6364
6465 self .output_settings (settings , spider )
Original file line number Diff line number Diff line change @@ -156,6 +156,23 @@ def test_log_all_should_not_return_aws_secret_key_value_by_default(caplog):
156156 assert 'secret_value' not in caplog .text
157157
158158
159+ def test_log_all_should_not_return_password_value_by_default (caplog ):
160+ settings = {
161+ "SETTINGS_LOGGING_ENABLED" : True ,
162+ "test_password" : 'secret_value1' ,
163+ "PASSWORD_TEST" : 'secret_value2' ,
164+ }
165+
166+ spider = MockSpider (settings )
167+ logger = SpiderSettingsLogging ()
168+ with caplog .at_level (logging .INFO ):
169+ logger .spider_closed (spider )
170+
171+ assert '"test_password": "*************"' in caplog .text
172+ assert '"PASSWORD_TEST": "*************"' in caplog .text
173+ assert 'secret_value' not in caplog .text
174+
175+
159176def test_log_all_should_return_only_the_custom_regex_data_masked_if_MASKED_SENSITIVE_SETTINGS_REGEX_LIST_configured (caplog ):
160177 settings = {
161178 "SETTINGS_LOGGING_ENABLED" : True ,
You can’t perform that action at this time.
0 commit comments