/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Middleware
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Middleware/CspMiddleware.php (3119B)
*/
protected $_defaultConfig = [
'scriptNonce' => false,
'styleNonce' => false,
];
/**
* Constructor
*
* @param \ParagonIE\CSPBuilder\CSPBuilder|array $csp CSP object or config array
* @param array
$config Configuration options.
* @throws \RuntimeException
*/
public function __construct($csp, array $config = [])
{
if (!class_exists(CSPBuilder::class)) {
throw new RuntimeException('You must install paragonie/csp-builder to use CspMiddleware');
}
$this->setConfig($config);
if (!$csp instanceof CSPBuilder) {
$csp = new CSPBuilder($csp);
}
$this->csp = $csp;
}
/**
* Add nonces (if enabled) to the request and apply the CSP header to the response.
*
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
* @param \Psr\Http\Server\RequestHandlerInterface $handler The request handler.
* @return \Psr\Http\Message\ResponseInterface A response.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->getConfig('scriptNonce')) {
$request = $request->withAttribute('cspScriptNonce', $this->csp->nonce('script-src'));
}
if ($this->getconfig('styleNonce')) {
$request = $request->withAttribute('cspStyleNonce', $this->csp->nonce('style-src'));
}
$response = $handler->handle($request);
/** @var \Psr\Http\Message\ResponseInterface */
return $this->csp->injectCSPHeader($response);
}
}