File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
src/Ubiquity/security/csp Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,8 @@ public static function getNonce(string $name): string {
6262 public static function getHash (string $ name , string $ code , string $ algo = 'sha256 ' ): string {
6363 $ code = \preg_replace ('/\r\n/ ' , '\n ' , $ code );
6464 $ hash = \base64_encode (\hash ($ algo , $ code , true ));
65- $ hash= "$ algo- $ hash " ;
66- if (isset (self ::$ onGenerate ) && !URequest::isAjax ()) {
65+ $ hash = "$ algo- $ hash " ;
66+ if (isset (self ::$ onGenerate ) && ! URequest::isAjax ()) {
6767 $ onG = self ::$ onGenerate ;
6868 $ onG ($ name , $ hash , $ algo );
6969 }
@@ -101,6 +101,16 @@ public static function addCsp(?bool $reportOnly = null): ContentSecurity {
101101 return self ::$ csp [] = new ContentSecurity ($ reportOnly ?? self ::$ reportOnly );
102102 }
103103
104+ /**
105+ * Returns a default ContentSecurity object.
106+ *
107+ * @param bool $reportOnly
108+ * @return ContentSecurity
109+ */
110+ public static function defaultCsp (?bool $ reportOnly = null ): ContentSecurity {
111+ return self ::$ csp ['default ' ] ??= new ContentSecurity ($ reportOnly ?? self ::$ reportOnly );
112+ }
113+
104114 /**
105115 * Removes all CSP objects.
106116 */
You can’t perform that action at this time.
0 commit comments