1
+ <?php
2
+ use bicf \securityheaders ;
3
+
4
+ /**
5
+ * Class Response
6
+ * ```php
7
+ * [
8
+ * 'components' => [
9
+ * 'response' => [
10
+ * 'class' => 'bicf\securityheaders\Response',
11
+ * 'on afterPrepare' => ['bicf\securityheaders\Response','modulesInit'],
12
+ * 'on afterSend' => ['bicf\securityheaders\Response','modulesSendHeaders'],
13
+ * 'modules' => [
14
+ * 'XContentTypeOptions'=>[
15
+ * 'class' => 'bicf\securityheaders\modules\HeaderXContentTypeOptions',
16
+ * 'value' => 'nosniff',
17
+ * ],
18
+ * 'AccessControlAllowMethods'=>[
19
+ * 'class' => 'bicf\securityheaders\modules\HeaderAccessControlAllowMethods',
20
+ * 'value' => 'GET',
21
+ * ],
22
+ * 'AccessControlAllowOrigin'=>[
23
+ * 'class' => 'bicf\securityheaders\modules\HeaderAccessControlAllowOrigin',
24
+ * 'value' => 'https://api.example.com',
25
+ * ],
26
+ * 'ContentSecurityPolicyAcl'=>[
27
+ * 'class' => 'bicf\securityheaders\modules\HeaderContentSecurityPolicyAcl',
28
+ * 'enabled' => false,
29
+ * 'policies' => [
30
+ * 'default-src' => "'self'",
31
+ * 'frame-src' => "'self' www.facebook.com www.youtube.com www.google.com",
32
+ * 'img-src' => "'self' www.google-analytics.com",
33
+ * 'font-src' => "'self' fonts.gstatic.com maxcdn.bootstrapcdn.com",
34
+ * 'media-src' => "'self'",
35
+ * 'script-src' => "'self' www.google-analytics.com",
36
+ * 'style-src' => "'self' maxcdn.bootstrapcdn.com",
37
+ * 'connect-src' => "'self'",
38
+ * 'report-uri' => "/report-csp-acl",
39
+ * ],
40
+ * ],
41
+ * 'ContentSecurityPolicyMonitor'=>[
42
+ * 'class' => 'bicf\securityheaders\modules\HeaderContentSecurityPolicyMonitor',
43
+ * 'policies' => [
44
+ * 'default-src' => "'self'",
45
+ * 'frame-src' => "'self' www.facebook.com www.youtube.com www.google.com",
46
+ * 'img-src' => "'self' www.google-analytics.com",
47
+ * 'font-src' => "'self' fonts.gstatic.com maxcdn.bootstrapcdn.com",
48
+ * 'media-src' => "'self'",
49
+ * 'script-src' => "'self' www.google-analytics.com",
50
+ * 'style-src' => "'self' maxcdn.bootstrapcdn.com",
51
+ * 'connect-src' => "'self'",
52
+ * 'report-uri' => "/report-csp-acl",
53
+ * ],
54
+ * ],
55
+ * ],
56
+ * ],
57
+ * ],
58
+ * ]
59
+ *
60
+ * ```
61
+ */
62
+ class Response extends \yii \web \Response
63
+ {
64
+ /** @var array of header modules default is empty
65
+ * use the configuration to populate the array
66
+ */
67
+ public $ modules =array ();
68
+
69
+ protected function modulesInit ()
70
+ {
71
+ foreach ($ this ->modules as $ module ){
72
+ $ module ->init ();
73
+ }
74
+ }
75
+
76
+ protected function modulesSendHeaders ()
77
+ {
78
+ foreach ($ this ->modules as $ module ){
79
+ $ module ->run ();
80
+ }
81
+ }
82
+ }
0 commit comments