Browse Source

feat: Deal with special characters in PII config (#17137)

* feat: Deal with special characters in PII config

* ref: Bump relay
Markus Unterwaditzer 5 years ago
parent
commit
8f5c726a36
3 changed files with 9 additions and 20 deletions
  1. 1 1
      requirements-base.txt
  2. 1 7
      src/sentry/datascrubbing.py
  3. 7 12
      tests/sentry/test_datascrubbing.py

+ 1 - 1
requirements-base.txt

@@ -49,7 +49,7 @@ redis-py-cluster==1.3.4
 redis>=2.10.3,<2.10.6
 redis>=2.10.3,<2.10.6
 requests-oauthlib==1.2.0
 requests-oauthlib==1.2.0
 requests[security]>=2.20.0,<2.21.0
 requests[security]>=2.20.0,<2.21.0
-sentry-relay>=0.5.3,<0.6.0
+sentry-relay>=0.5.4,<0.6.0
 sentry-sdk>=0.13.5
 sentry-sdk>=0.13.5
 simplejson>=3.2.0,<3.9.0
 simplejson>=3.2.0,<3.9.0
 six>=1.10.0,<1.11.0
 six>=1.10.0,<1.11.0

+ 1 - 7
src/sentry/datascrubbing.py

@@ -1,6 +1,5 @@
 from __future__ import absolute_import
 from __future__ import absolute_import
 
 
-import re
 import copy
 import copy
 
 
 import sentry_relay
 import sentry_relay
@@ -9,8 +8,6 @@ import six
 from sentry.utils import metrics
 from sentry.utils import metrics
 from sentry.utils.canonical import CanonicalKeyDict
 from sentry.utils.canonical import CanonicalKeyDict
 
 
-_KEY_RE = re.compile(u"^[a-zA-Z0-9_-]+$")
-
 
 
 def _escape_key(key):
 def _escape_key(key):
     """
     """
@@ -18,11 +15,8 @@ def _escape_key(key):
 
 
     If this fails and we cannot represent the key, return None
     If this fails and we cannot represent the key, return None
     """
     """
-    if _KEY_RE.match(key):
-        return key
 
 
-    # TODO: Quote string here once it's implemented in Relay
-    return None
+    return u"'{}'".format(key.replace("'", "''"))
 
 
 
 
 def _path_selectors_from_diff(old_data, data):
 def _path_selectors_from_diff(old_data, data):

+ 7 - 12
tests/sentry/test_datascrubbing.py

@@ -11,26 +11,21 @@ def test_path_selectors_from_diff():
     def f(old_event, event):
     def f(old_event, event):
         return list(_path_selectors_from_diff(old_event, event))
         return list(_path_selectors_from_diff(old_event, event))
 
 
-    assert f({}, {"foo": {"bar": ["baz"]}}) == ["foo", "foo.**"]
+    assert f({}, {"foo": {"bar": ["baz"]}}) == ["'foo'", "'foo'.**"]
     assert f({"foo": {"bar": ["baz"]}}, {}) == []
     assert f({"foo": {"bar": ["baz"]}}, {}) == []
-    assert f({"foo": {"bar": ["bam"]}}, {"foo": {"bar": ["baz"]}}) == ["foo.bar.0", "foo.bar.0.**"]
+    assert f({"foo": {"bar": ["bam"]}}, {"foo": {"bar": ["baz"]}}) == [
+        "'foo'.'bar'.0",
+        "'foo'.'bar'.0.**",
+    ]
     assert f(42, {}) == [None, "**"]
     assert f(42, {}) == [None, "**"]
-    assert f({"foo": {"bar": []}}, {"foo": {"bar": [42]}}) == ["foo.bar.0", "foo.bar.0.**"]
+    assert f({"foo": {"bar": []}}, {"foo": {"bar": [42]}}) == ["'foo'.'bar'.0", "'foo'.'bar'.0.**"]
     assert f({"foo": {"bar": [42]}}, {"foo": {"bar": []}}) == []
     assert f({"foo": {"bar": [42]}}, {"foo": {"bar": []}}) == []
 
 
     # unicode vs bytes
     # unicode vs bytes
     assert f({"foo": {"bar": b"baz"}}, {"foo": {"bar": u"baz"}}) == []
     assert f({"foo": {"bar": b"baz"}}, {"foo": {"bar": u"baz"}}) == []
 
 
 
 
-@pytest.mark.parametrize(
-    "field",
-    [
-        u"aaa",
-        pytest.param(u"aää", marks=pytest.mark.xfail),
-        pytest.param(u"a a", marks=pytest.mark.xfail),
-        pytest.param(u"a\na", marks=pytest.mark.xfail),
-    ],
-)
+@pytest.mark.parametrize("field", [u"aaa", u"aää", u"a a", u"a\na", u"a'a"])
 def test_scrub_data_in_processing(field):
 def test_scrub_data_in_processing(field):
     project_config = ProjectConfig(
     project_config = ProjectConfig(
         None,
         None,