$value) { if (isset($this->{$setting})) { $this->{$setting} = $value; } } } //-------------------------------------------------------------------- /** * Compiles and sets the appropriate headers in the request. * * Should be called just prior to sending the response to the user agent. * * @param ResponseInterface $response */ public function finalize(ResponseInterface &$response) { $this->generateNonces($response); $this->buildHeaders($response); } //-------------------------------------------------------------------- /** * If TRUE, nothing will be restricted. Instead all violations will * be reported to the reportURI for monitoring. This is useful when * you are just starting to implement the policy, and will help * determine what errors need to be addressed before you turn on * all filtering. * * @param boolean|true $value * * @return $this */ public function reportOnly(bool $value = true) { $this->reportOnly = $value; return $this; } //-------------------------------------------------------------------- /** * Adds a new base_uri value. Can be either a URI class or a simple string. * * base_uri restricts the URLs that can appear in a page’s element. * * @see http://www.w3.org/TR/CSP/#directive-base-uri * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function addBaseURI($uri, ?bool $explicitReporting = null) { $this->addOption($uri, 'baseURI', $explicitReporting ?? $this->reportOnly); return $this; } //-------------------------------------------------------------------- /** * Adds a new valid endpoint for a form's action. Can be either * a URI class or a simple string. * * child-src lists the URLs for workers and embedded frame contents. * For example: child-src https://youtube.com would enable embedding * videos from YouTube but not from other origins. * * @see http://www.w3.org/TR/CSP/#directive-child-src * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function addChildSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri, 'childSrc', $explicitReporting ?? $this->reportOnly); return $this; } //-------------------------------------------------------------------- /** * Adds a new valid endpoint for a form's action. Can be either * a URI class or a simple string. * * connect-src limits the origins to which you can connect * (via XHR, WebSockets, and EventSource). * * @see http://www.w3.org/TR/CSP/#directive-connect-src * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function addConnectSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri, 'connectSrc', $explicitReporting ?? $this->reportOnly); return $this; } //-------------------------------------------------------------------- /** * Adds a new valid endpoint for a form's action. Can be either * a URI class or a simple string. * * default_src is the URI that is used for many of the settings when * no other source has been set. * * @see http://www.w3.org/TR/CSP/#directive-default-src * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function setDefaultSrc($uri, ?bool $explicitReporting = null) { $this->defaultSrc = [(string) $uri => $explicitReporting ?? $this->reportOnly]; return $this; } //-------------------------------------------------------------------- /** * Adds a new valid endpoint for a form's action. Can be either * a URI class or a simple string. * * font-src specifies the origins that can serve web fonts. * * @see http://www.w3.org/TR/CSP/#directive-font-src * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function addFontSrc($uri, ?bool $explicitReporting = null) { $this->addOption($uri, 'fontSrc', $explicitReporting ?? $this->reportOnly); return $this; } //-------------------------------------------------------------------- /** * Adds a new valid endpoint for a form's action. Can be either * a URI class or a simple string. * * @see http://www.w3.org/TR/CSP/#directive-form-action * * @param string|array $uri * @param boolean|null $explicitReporting * * @return $this */ public function addFormAction($uri, ?bool $explicitReporting = null) { $this->addOption($uri, 'formAction', $explicitReporting ?? $this->reportOnly); return $this; } //-------------------------------------------------------------------- /** * Adds a new resource that should allow embedding the resource using * ,