@@ -284,7 +284,7 @@ class ContentSecurityPolicyHeaderBuilder
284
284
*
285
285
* @var string
286
286
*/
287
- const FRAME_OPTION_DENY = 'DENY ' ;
287
+ const FRAME_OPTION_DENY = 'DENY ' ;
288
288
289
289
/**
290
290
* Valid value for the 'X-Frame-Options' header. UA's will refuse to load any resource that sets the value of this
@@ -293,7 +293,7 @@ class ContentSecurityPolicyHeaderBuilder
293
293
*
294
294
* @var string
295
295
*/
296
- const FRAME_OPTION_SAME_ORIGIN = 'SAMEORIGIN ' ;
296
+ const FRAME_OPTION_SAME_ORIGIN = 'SAMEORIGIN ' ;
297
297
298
298
/**
299
299
* Valid value for the 'X-Frame-Options' header. UA's will refuse to load any resource that sets the value of this
@@ -302,7 +302,7 @@ class ContentSecurityPolicyHeaderBuilder
302
302
*
303
303
* @var string
304
304
*/
305
- const FRAME_OPTION_ALLOW_FROM = 'ALLOW-FROM %s ' ;
305
+ const FRAME_OPTION_ALLOW_FROM = 'ALLOW-FROM %s ' ;
306
306
307
307
/**
308
308
* All valid values for the 'X-Frame-Options' header.
@@ -378,6 +378,16 @@ class ContentSecurityPolicyHeaderBuilder
378
378
*/
379
379
protected $ reportUri = null ;
380
380
381
+ /**
382
+ * @var string
383
+ */
384
+ protected $ upgradeInsecureRequestsDirective = 'upgrade-insecure-requests ' ;
385
+
386
+ /**
387
+ * @var bool
388
+ */
389
+ protected $ upgradeInsecureRequests = false ;
390
+
381
391
/**
382
392
* @param bool $enforce
383
393
*/
@@ -451,6 +461,14 @@ public function setFrameOptions($policy, $origin = '')
451
461
$ this ->frameOptionsValue = trim (sprintf ($ policy , $ origin ));
452
462
}
453
463
464
+ /**
465
+ * @param bool $upgrade
466
+ */
467
+ public function setUpgradeInsecureRequests ($ upgrade )
468
+ {
469
+ $ this ->upgradeInsecureRequests = $ upgrade ;
470
+ }
471
+
454
472
/**
455
473
* @param string $uri
456
474
*/
@@ -543,7 +561,8 @@ public function addSourceExpression($directive, $expression)
543
561
if (!(
544
562
isset ($ this ->directives [$ directive ]['expressions ' ])
545
563
&& is_array ($ this ->directives [$ directive ]['expressions ' ])
546
- )) {
564
+ )
565
+ ) {
547
566
$ this ->directives [$ directive ]['expressions ' ] = [];
548
567
}
549
568
@@ -601,6 +620,10 @@ public function getValue()
601
620
$ directives [] = sprintf ('%s %s ' , 'reflected-xss ' , $ this ->reflectedXssValue );
602
621
}
603
622
623
+ if ($ this ->upgradeInsecureRequests ) {
624
+ $ directives [] = $ this ->upgradeInsecureRequestsDirective ;
625
+ }
626
+
604
627
if (!is_null ($ this ->referrerValue )) {
605
628
$ directives [] = sprintf ('%s %s ' , 'referrer ' , $ this ->referrerValue );
606
629
}
@@ -628,7 +651,7 @@ public function getHeaders($includeLegacy)
628
651
$ headers = [];
629
652
} else {
630
653
$ headers [] = [
631
- 'name ' => $ this ->getHeaderName (),
654
+ 'name ' => $ this ->getHeaderName (),
632
655
'value ' => $ value
633
656
];
634
657
}
@@ -691,7 +714,7 @@ private function parseDirectiveValue($directive)
691
714
}
692
715
}
693
716
694
- return trim (implode (' ' , array_map (function ($ value ) {
717
+ return trim (implode (' ' , array_map (function ($ value ) {
695
718
return $ this ->encodeDirectiveValue ($ value );
696
719
}, $ expressions )));
697
720
}
@@ -748,21 +771,21 @@ private function getLegacyXssHeader($reflectedXssValue)
748
771
switch ($ reflectedXssValue ) {
749
772
case 'allow ' :
750
773
$ header = [
751
- 'name ' => $ this ->legacyXssHeader ,
774
+ 'name ' => $ this ->legacyXssHeader ,
752
775
'value ' => '0 '
753
776
];
754
777
break ;
755
778
756
779
case 'filter ' :
757
780
$ header = [
758
- 'name ' => $ this ->legacyXssHeader ,
781
+ 'name ' => $ this ->legacyXssHeader ,
759
782
'value ' => '1 '
760
783
];
761
784
break ;
762
785
763
786
case 'block ' :
764
787
$ header = [
765
- 'name ' => $ this ->legacyXssHeader ,
788
+ 'name ' => $ this ->legacyXssHeader ,
766
789
'value ' => '1; mode=block '
767
790
];
768
791
break ;
@@ -781,7 +804,7 @@ private function getLegacyFrameOptionsHeader()
781
804
}
782
805
783
806
return [
784
- 'name ' => $ this ->legacyFrameOptionsHeader ,
807
+ 'name ' => $ this ->legacyFrameOptionsHeader ,
785
808
'value ' => $ this ->frameOptionsValue
786
809
];
787
810
}
0 commit comments