|
@@ -1,12 +1,12 @@
|
|
|
-__all__ = ("Csp", "Hpkp", "ExpectCT", "ExpectStaple")
|
|
|
-
|
|
|
-from urllib.parse import urlsplit, urlunsplit
|
|
|
-
|
|
|
from sentry.interfaces.base import Interface
|
|
|
+from sentry.security import csp
|
|
|
from sentry.utils import json
|
|
|
from sentry.utils.cache import memoize
|
|
|
from sentry.web.helpers import render_to_string
|
|
|
|
|
|
+__all__ = ("Csp", "Hpkp", "ExpectCT", "ExpectStaple")
|
|
|
+
|
|
|
+
|
|
|
# Default block list sourced from personal experience as well as
|
|
|
# reputable blogs from Twitter and Dropbox
|
|
|
DEFAULT_DISALLOWED_SOURCES = (
|
|
@@ -158,7 +158,6 @@ class Csp(SecurityReport):
|
|
|
>>> }
|
|
|
"""
|
|
|
|
|
|
- LOCAL = "'self'"
|
|
|
score = 1300
|
|
|
display_score = 1300
|
|
|
|
|
@@ -182,7 +181,7 @@ class Csp(SecurityReport):
|
|
|
|
|
|
@memoize
|
|
|
def normalized_blocked_uri(self):
|
|
|
- return self._normalize_uri(self.blocked_uri)
|
|
|
+ return csp.normalize_value(self.blocked_uri)
|
|
|
|
|
|
@memoize
|
|
|
def local_script_violation_type(self):
|
|
@@ -192,35 +191,10 @@ class Csp(SecurityReport):
|
|
|
if (
|
|
|
self.violated_directive
|
|
|
and self.effective_directive == "script-src"
|
|
|
- and self.normalized_blocked_uri == self.LOCAL
|
|
|
+ and self.normalized_blocked_uri == csp.LOCAL
|
|
|
):
|
|
|
if "'unsafe-inline'" in self.violated_directive:
|
|
|
return "unsafe-inline"
|
|
|
elif "'unsafe-eval'" in self.violated_directive:
|
|
|
return "unsafe-eval"
|
|
|
return None
|
|
|
-
|
|
|
- def _normalize_uri(self, value):
|
|
|
- if value in ("", self.LOCAL, self.LOCAL.strip("'")):
|
|
|
- return self.LOCAL
|
|
|
-
|
|
|
- # A lot of these values get reported as literally
|
|
|
- # just the scheme. So a value like 'data' or 'blob', which
|
|
|
- # are valid schemes, just not a uri. So we want to
|
|
|
- # normalize it into a uri.
|
|
|
- if ":" not in value:
|
|
|
- scheme, hostname = value, ""
|
|
|
- else:
|
|
|
- try:
|
|
|
- scheme, hostname = urlsplit(value)[:2]
|
|
|
- except ValueError:
|
|
|
- # best effort url splitting
|
|
|
- scheme, _, rest = value.partition("://")
|
|
|
- hostname, _, _ = rest.partition("/")
|
|
|
-
|
|
|
- if scheme in ("http", "https"):
|
|
|
- return hostname
|
|
|
- return self._unsplit(scheme, hostname)
|
|
|
-
|
|
|
- def _unsplit(self, scheme, hostname):
|
|
|
- return urlunsplit((scheme, hostname, "", None, None))
|