text = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext(); if (!$responseContext?->has(CspHandler::class)) { return null; } return $responseContext->get(CspHandler::class)->getNonce($directive); } /** * Adds a source to the given CSP directive. */ public function addCspSource(array|string $directives, string $source): void { $responseContext = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext(); if (!$responseContext?->has(CspHandler::class)) { return; } $csp = $responseContext->get(CspHandler::class); foreach ((array) $directives as $directive) { $csp->addSource($directive, $source); } } /** * Adds a CSP hash for the given script. */ public function addCspHash(string $directive, string $script, string $algorithm = 'sha384'): void { $responseContext = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext(); if (!$responseContext?->has(CspHandler::class)) { return; } $csp = $responseContext->get(CspHandler::class); $csp->addHash($directive, $script, $algorithm); } /** * @deprecated Deprecated since Contao 5.3, to be removed in Contao 6; * use cspUnsafeInlineStyle() instead. */ public function cspInlineStyle(string $style, string $algorithm = 'sha384'): string { trigger_deprecation('contao/core-bundle', '5.3', 'Using "%s()" has been deprecated and will no longer work in Contao 6. Use "cspUnsafeInlineStyle()" instead.', __METHOD__); return $this->cspUnsafeInlineStyle($style, $algorithm); } /** * Adds a CSP hash for a given inline style and also adds the 'unsafe-hashes' source to the directive automatically. * * ATTENTION: Only pass trusted styles to this method! */ public function cspUnsafeInlineStyle(string $style, string $algorithm = 'sha384'): string { $responseContext = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext(); if ($responseContext?->has(CspHandler::class)) { $csp = $responseContext->get(CspHandler::class); $csp ->addHash('style-src', $style, $algorithm) ->addSource('style-src', "'unsafe-hashes'") ; } return $style; } /** * Extracts all inline CSS style attributes of a given HTML string and automatically adds CSP hashes for those * to the current response context. The list of allowed styles can be configured in contao.csp.allowed_inline_styles. */ public function cspInlineStyles(string|null $html): string|null { if (!$html) { return $html; } $responseContext = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext(); if (!$responseContext?->has(CspHandler::class)) { return $html; } $styleProcessor = System::getContainer()->get('contao.csp.wysiwyg_style_processor'); if (!$styles = $styleProcessor->extractStyles($html)) { return $html; } $csp = $responseContext->get(CspHandler::class); foreach ($styles as $style) { $csp->addHash('style-src', $style); } $csp->addSource('style-src', "'unsafe-hashes'"); return $html; } /** * Render a figure * * The provided configuration array is used to configure a FigureBuilder. * If not explicitly set, the default template "image.html5" will be used * to render the results. To use the core's default Twig template, pass * "@ContaoCore/Image/Studio/figure.html.twig" as $template argument. * * @param int|string|FilesModel|ImageInterface $from Can be a FilesModel, an ImageInterface, a tl_files UUID/ID/path or a file system path * @param int|string|array|PictureConfiguration|null $size A picture size configuration or reference * @param array $configuration Configuration for the FigureBuilder * @param string $template A Contao or Twig template * * @return string|null Returns null if the resource is invalid */ public function figure($from, $size, $configuration = array(), $template = 'image') { return System::getContainer()->get('contao.image.studio.figure_renderer')->render($from, $size, $configuration, $template); } /** * Returns an asset path * * @param string $path * @param string|null $packageName * * @return string */ public function asset($path, $packageName = null) { return System::getContainer()->get('assets.packages')->getUrl($path, $packageName); } /** * Returns an asset version * * @param string $path * @param string|null $packageName * * @return string */ public function assetVersion($path, $packageName = null) { return System::getContainer()->get('assets.packages')->getVersion($path, $packageName); } /** * Returns a container parameter * * @param string $strKey * * @return mixed */ public function param($strKey) { return System::getContainer()->getParameter($strKey); } /** * Prefixes a relative URL * * @param string $url * * @return string */ public function prefixUrl($url) { if (!Validator::isRelativeUrl($url)) { return $url; } return Environment::get('path') . '/' . $url; } } An Error Occurred: Internal Server Error

Oops! An Error Occurred

The server returned a "500 Internal Server Error".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.