handlers.py 882 B

1234567891011121314151617181920212223242526272829303132
  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 ...base.handlers import APIHandler
  6. from . import csp_report_uri
  7. class CSPReportHandler(APIHandler):
  8. '''Accepts a content security policy violation report'''
  9. _track_activity = False
  10. def skip_check_origin(self):
  11. """Don't check origin when reporting origin-check violations!"""
  12. return True
  13. def check_xsrf_cookie(self):
  14. # don't check XSRF for CSP reports
  15. return
  16. @web.authenticated
  17. def post(self):
  18. '''Log a content security policy violation report'''
  19. self.log.warning("Content security violation: %s",
  20. self.request.body.decode('utf8', 'replace'))
  21. default_handlers = [
  22. (csp_report_uri, CSPReportHandler)
  23. ]