Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
Closed
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
16 changes: 16 additions & 0 deletions raven/contrib/django/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.http import HttpRequest
from django.template import TemplateSyntaxError
from django.template.loader import LoaderOrigin
from django.utils.http import urlencode

from raven.base import Client
from raven.contrib.django.utils import get_data_from_template, get_host
Expand Down Expand Up @@ -80,6 +81,18 @@ def get_data_from_request(self, request):
except Exception:
# assume we had a partial read:
data = '<unavailable>'

# hide sensitive data
if hasattr(request, 'sensitive_post_parameters'):
if request.sensitive_post_parameters == '__ALL__':
data = '<hidden>'
elif data != '<unavailable>':
qs = _urlparse.parse_qs(data)
for param in request.sensitive_post_parameters:
if param in qs:
qs[param] = '<hidden>'
data = urlencode(qs, doseq=True)

else:
data = None

Expand All @@ -94,6 +107,9 @@ def get_data_from_request(self, request):
'cookies': dict(request.COOKIES),
'headers': dict(get_headers(environ)),
'env': dict(get_environ(environ)),
'sensitive_post_params':
request.sensitive_post_parameters and
request.sensitive_post_parameters or False
}
})

Expand Down
15 changes: 11 additions & 4 deletions raven/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def sanitize(self, key, value):

key = key.lower()
for field in self.FIELDS:
if field in key:
if self.FIELDS == "__ALL__" or field in key:
# store mask as a fixed length for security
return self.MASK
return value
Expand Down Expand Up @@ -104,10 +104,17 @@ def filter_http(self, data):
data[n] = varmap(self.sanitize, data[n])

def process(self, data, **kwargs):
if 'sentry.interfaces.Stacktrace' in data:
self.filter_stacktrace(data['sentry.interfaces.Stacktrace'])

if 'sentry.interfaces.Http' in data:
if 'sensitive_post_params' in data['sentry.interfaces.Http']:
Copy link
Member

Choose a reason for hiding this comment

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

we can just require the use of the raven middleware for this, and install a custom Django processor.

See raven.contrib.django.middleware.SentryMiddleware

It gives us access to the request object, and then we can have a SensitiveDataProcessor or something that we add to the default processors (for Django client) which applies this


if data['sentry.interfaces.Http']['sensitive_post_params'] == '__ALL__':
self.FIELDS = "__ALL__"
elif data['sentry.interfaces.Http']['sensitive_post_params']:
self.FIELDS = self.FIELDS.union(data['sentry.interfaces.Http']['sensitive_post_params'])

self.filter_http(data['sentry.interfaces.Http'])

if 'sentry.interfaces.Stacktrace' in data:
self.filter_stacktrace(data['sentry.interfaces.Stacktrace'])

return data