-
Notifications
You must be signed in to change notification settings - Fork 0
/
Csp.php
42 lines (34 loc) · 1014 Bytes
/
Csp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace LimeSoda\LsSecurityHeaders\Userfuncs;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
class Csp
{
/**
* @var ContentObjectRenderer
*/
private ContentObjectRenderer $cObj;
/**
* @param ContentObjectRenderer $cObj
* @return void
*/
public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
{
$this->cObj = $cObj;
}
/**
* @param string $_
* @param array $conf
* @return string
* @throws \Exception
*/
public function generateNonce(string $_, array $conf): string
{
$length = $this->cObj->cObjGetSingle($conf['length'], $conf['length.']);
$policy = $this->cObj->cObjGetSingle($conf['policy'], $conf['policy.']);
$nonce = bin2hex(random_bytes($length));
$GLOBALS['LS_SECURITY_HEADERS']['CSP_NONCE'][$policy][] = $nonce;
return $nonce;
}
}