@csrf_exempt
@require_POST
def cspreport(request):
 report = ('blocked-uri', 'violated-directive', 'original-policy')
 if (not waffle.sample_is_active('csp-store-reports')):
  return HttpResponse()
 try:
  v = json.loads(request.body)['csp-report']
  meta = request.META.copy()
  meta['PATH_INFO'] = v.get('document-uri', meta['PATH_INFO'])
  v = [(k, v[k]) for k in report if (k in v)]
  log_cef('CSPViolation', 5, meta, signature='CSPREPORT', msg='A client reported a CSP violation', cs6=v, cs6Label='ContentPolicy')
 except (KeyError, ValueError) as e:
  log.debug(('Exception in CSP report: %s' % e), exc_info=True)
  return HttpResponseBadRequest()
 return HttpResponse()

@ csrf_exempt @ require_POST def cspreport ( request ) : report = ( 'blocked-uri' , 'violated-directive' , 'original-policy' ) if ( not waffle . sample_is_active ( 'csp-store-reports' ) ) : return HttpResponse ( ) try : v = json . loads ( request . body ) [ 'csp-report' ] meta = request . META . copy ( ) meta [ 'PATH_INFO' ] = v . get ( 'document-uri' , meta [ 'PATH_INFO' ] ) v = [ ( k , v [ k ] ) for k in report if ( k in v ) ] log_cef ( 'CSPViolation' , 5 , meta , signature = 'CSPREPORT' , msg = 'A client reported a CSP violation' , cs6 = v , cs6Label = 'ContentPolicy' ) except ( KeyError , ValueError ) as e : log . debug ( ( 'Exception in CSP report: %s' % e ) , exc_info = True ) return HttpResponseBadRequest ( ) return HttpResponse ( )
accept csp reports and log them .