Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the call to re.findall with re.sub in _mask_credentials so matched values are not treated as regex patterns #413

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions project/tests/test_sensitive_data_in_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def test_mask_credentials_handles_prefixes(self):
def test_mask_credentials_handles_suffixes(self):
self.assertNotIn("secret", self._mask("username-with-suffix=secret"))

def test_mask_credentials_handles_regex_characters(self):
self.assertNotIn("secret", self._mask("password=secret++"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def test_mask_credentials_handles_complex_cases(self):
self.assertNotIn("secret", self._mask("foo=public&prefixed-uSeRname-with-suffix=secret&bar=public"))

Expand Down
8 changes: 1 addition & 7 deletions silk/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,9 @@ def replace_pattern_values(obj):
except Exception as e:
pattern = re.compile(r'({})[^=]*=(.*?)(&|$)'.format(key_string), re.M | re.I)
try:
results = re.findall(pattern, body)
body = re.sub(pattern, '\\1={}\\3'.format(RequestModelFactory.CLEANSED_SUBSTITUTE), body)
except Exception:
Logger.debug('{}'.format(str(e)))
else:
for res in results:
try:
body = re.sub(res[1], RequestModelFactory.CLEANSED_SUBSTITUTE, body)
except Exception:
Logger.debug('{}'.format(str(e)))
else:
body = json.dumps(replace_pattern_values(json_body))

Expand Down