11"use strict" ;
2-
2+
33function ReportingCSP ( reportURI , reportGroup ) {
4+ const REPORT_TO_SUPPORTED = false ;
5+ // TODO: figure out if we're running on a browser supporting the report-to
6+ // CSP directive, breaking report-uri, see
7+ // 1. https://www.w3.org/TR/CSP3/#directive-report-uri
8+ // 2. https://bugs.chromium.org/p/chromium/issues/detail?id=726634
9+ // 3. https://bugzilla.mozilla.org/show_bug.cgi?id=1391243
10+
411 const REPORT_TO = {
512 name : "Report-To" ,
613 value : JSON . stringify ( { "url" : reportURI ,
@@ -9,39 +16,40 @@ function ReportingCSP(reportURI, reportGroup) {
916 } ;
1017 return Object . assign (
1118 new CapsCSP ( new NetCSP (
12- ` report-uri ${ reportURI } ;`,
13- `; report-to ${ reportGroup } ;`
14- ) ) ,
19+ REPORT_TO_SUPPORTED ? `; report-to ${ reportGroup } ;`
20+ : ` report-uri ${ reportURI } ;`
21+ ) ) ,
1522 {
1623 reportURI,
1724 reportGroup,
1825 patchHeaders ( responseHeaders , capabilities ) {
1926 let header = null ;
20- let hasReportTo = false ;
27+ let needsReportTo = REPORT_TO_SUPPORTED ;
2128 for ( let h of responseHeaders ) {
2229 if ( this . isMine ( h ) ) {
2330 header = h ;
24- h . value = this . inject ( h . value , "" ) ;
25- } else if ( h . name === REPORT_TO . name && h . value === REPORT_TO . value ) {
26- hasReportTo = true ;
31+ h . value = "" ;
32+ } else if ( needsReportTo &&
33+ h . name === REPORT_TO . name && h . value === REPORT_TO . value ) {
34+ needsReportTo = false ;
2735 }
2836 }
2937
3038 let blocker = capabilities && this . buildFromCapabilities ( capabilities ) ;
3139 if ( blocker ) {
32- if ( ! hasReportTo ) {
40+ if ( needsReportTo ) {
3341 responseHeaders . push ( REPORT_TO ) ;
3442 }
3543 if ( header ) {
36- header . value = this . inject ( header . value , blocker ) ;
44+ header . value = blocker ;
3745 } else {
3846 header = this . asHeader ( blocker ) ;
3947 responseHeaders . push ( header ) ;
4048 }
4149 }
42-
50+
4351 return header ;
4452 }
4553 }
4654 ) ;
47- }
55+ }
0 commit comments