handlers.py 1022 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Tornado handlers for security logging."""
  2. # Copyright (c) Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from tornado import web
  5. from jupyter_server.auth.decorator import authorized
  6. from ...base.handlers import APIHandler
  7. from . import csp_report_uri
  8. AUTH_RESOURCE = "csp"
  9. class CSPReportHandler(APIHandler):
  10. """Accepts a content security policy violation report"""
  11. auth_resource = AUTH_RESOURCE
  12. _track_activity = False
  13. def skip_check_origin(self):
  14. """Don't check origin when reporting origin-check violations!"""
  15. return True
  16. def check_xsrf_cookie(self):
  17. """Don't check XSRF for CSP reports."""
  18. return
  19. @web.authenticated
  20. @authorized
  21. def post(self):
  22. """Log a content security policy violation report"""
  23. self.log.warning(
  24. "Content security violation: %s",
  25. self.request.body.decode("utf8", "replace"),
  26. )
  27. default_handlers = [(csp_report_uri, CSPReportHandler)]