Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Fix SanitizePassword to work with binary types of http data. #781

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion raven/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ def filter_http(self, data):
if n not in data:
continue

if isinstance(data[n], six.string_types) and '=' in data[n]:
if ((isinstance(data[n], six.string_types) and '=' in data[n]) or
isinstance(data[n], six.binary_type)):
# at this point we've assumed it's a standard HTTP query
if isinstance(data[n], six.binary_type):
data[n] = data[n].decode()
querybits = []
for bit in data[n].split('&'):
chunk = bit.split('=')
Expand Down
15 changes: 15 additions & 0 deletions tests/processors/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import six
from mock import Mock

import raven
Expand Down Expand Up @@ -119,6 +120,20 @@ def test_http(self):
self.assertTrue(n in http)
self._check_vars_sanitized(http[n], proc)

def test_http_data_as_bytes(self):
data = get_http_data()
data['request']['data'] = six.b(
'foo=bar&password=secury')

proc = SanitizePasswordsProcessor(Mock())
result = proc.process(data)

self.assertTrue('request' in result)
http = result['request']

self.assertEqual(
http['data'], 'foo=bar&password=%(m)s' % dict(m=proc.MASK))

def test_querystring_as_string(self):
data = get_http_data()
data['request']['query_string'] = 'foo=bar&password=hello&the_secret=hello'\
Expand Down