Skip to content

Commit

Permalink
Merge pull request #413 from rollbar/pawel/cover_sensitive_post_param…
Browse files Browse the repository at this point in the history
…s_django

handling sensitive_post_parameters decorator in django
  • Loading branch information
pawelsz-rb committed Jul 27, 2022
2 parents 4eb8a80 + fdfa372 commit 3cd8e6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ jobs:
# certifi dropped support for Python 2 in 2020.4.5.2 but only started
# using Python 3 syntax in 2022.5.18. 2021.10.8 is the last release with
# Python 2 support.
run: pip install certifi==2021.10.8
run: pip install certifi==2021.10.8 requests==2.27.1

- name: Install Python 3.4 dependencies
if: ${{ contains(matrix.python-version, '3.4') }}
Expand Down
11 changes: 11 additions & 0 deletions rollbar/contrib/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def _should_ignore_404(url):
url_patterns = getattr(settings, 'ROLLBAR', {}).get('ignorable_404_urls', ())
return any(p.search(url) for p in url_patterns)

def _apply_sensitive_post_params(request):
if request.sensitive_post_parameters:
mutable = request.POST._mutable
request.POST._mutable = True
for param in request.sensitive_post_parameters:
if param in request.POST:
request.POST[param] = "******"
request.POST._mutable = mutable

class RollbarNotifierMiddleware(MiddlewareMixin):
def __init__(self, get_response=None):
Expand Down Expand Up @@ -276,6 +284,8 @@ def process_response(self, request, response):
def process_exception(self, request, exc):
if isinstance(exc, Http404) and _should_ignore_404(request.get_full_path()):
return
_apply_sensitive_post_params(request)

rollbar.report_exc_info(
sys.exc_info(),
request,
Expand Down Expand Up @@ -305,6 +315,7 @@ def process_response(self, request, response):
else:
raise Http404()
except Exception as exc:
_apply_sensitive_post_params(request)
rollbar.report_exc_info(
sys.exc_info(),
request,
Expand Down

0 comments on commit 3cd8e6d

Please sign in to comment.