Skip to content

Commit dcd9a49

Browse files
committed
add defaultCsp
1 parent c9e7625 commit dcd9a49

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Ubiquity/security/csp/ContentSecurityManager.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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
*/

0 commit comments

Comments
 (0)