From 54192ad2dfcf3b896be1e2bf24192bc80cd9fc72 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 21 Jan 2016 09:26:31 -0800 Subject: [PATCH] Fix non ascii bytes in password sanitization. This fixes #727 --- CHANGES | 6 ++++++ raven/processors.py | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 392eaf72..c2141ee9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Version 5.10.1 +-------------- + +* Fixed a problem where bytes as keys in dictionaries caused problems + on data sanitization if those bytes were outside of the ASCII range. + Version 5.10.0 -------------- diff --git a/raven/processors.py b/raven/processors.py index 3f1a74b6..3243d830 100644 --- a/raven/processors.py +++ b/raven/processors.py @@ -9,7 +9,7 @@ from __future__ import absolute_import import re -from raven._compat import string_types, text_type +from raven._compat import string_types from raven.utils import varmap @@ -94,7 +94,12 @@ class SanitizePasswordsProcessor(Processor): if not key: # key can be a NoneType return value - key = text_type(key).lower() + # Just in case we have bytes here, we want to make them into text + # properly without failing so we can perform our check. + if isinstance(key, bytes): + key = key.decode('utf-8', 'replace') + + key = key.lower() for field in self.FIELDS: if field in key: # store mask as a fixed length for security