Call to admin/config/system/csp results in TypeError

Created on 28 March 2025, about 2 months ago

Problem/Motivation

Unable to access the configuration form

Steps to reproduce

Go to admin/config/system/csp results in The website encountered an unexpected error. Try again later.
dblog message:
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/web132/drupal/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of /var/www/web132/drupal/web/core/lib/Drupal/Component/Utility/Html.php).
Backtrace:
#0 /var/www/web132/drupal/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(238): Drupal\Component\Utility\Html::escape()
#1 /var/www/web132/drupal/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(211): Drupal\Component\Render\FormattableMarkup::placeholderEscape()
#2 /var/www/web132/drupal/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat()
#3 /var/www/web132/drupal/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /var/www/web132/drupal/web/core/lib/Drupal/Core/Messenger/Messenger.php(54): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /var/www/web132/drupal/web/core/lib/Drupal/Core/Messenger/Messenger.php(46): Drupal\Core\Messenger\Messenger->addMessage()
#6 /var/www/web132/drupal/web/modules/contrib/csp/src/Form/CspSettingsForm.php(487): Drupal\Core\Messenger\Messenger->addError()
#7 [internal function]: Drupal\csp\Form\CspSettingsForm->buildForm()
#8 /var/www/web132/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(528): call_user_func_array()
#9 /var/www/web132/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(279): Drupal\Core\Form\FormBuilder->retrieveForm()
#10 /var/www/web132/drupal/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#11 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#12 /var/www/web132/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#13 /var/www/web132/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(593): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 /var/www/web132/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#15 /var/www/web132/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#16 /var/www/web132/drupal/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#17 /var/www/web132/drupal/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#18 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#19 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#20 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#21 /var/www/web132/drupal/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#22 /var/www/web132/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#23 /var/www/web132/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#24 /var/www/web132/drupal/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#25 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#26 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#28 /var/www/web132/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#29 /var/www/web132/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(709): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#30 /var/www/web132/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#31 {main}

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @johnwt
  • 🇮🇳India Raveen Kumar

    I have installed the module using composer require 'drupal/csp:^2.2'
    I am using drupal latest version i.e, Drupal : 11.1.5

    On visit of - admin/config/system/csp , I was able to access config form. As you can see my attached screenshot.

    Could you please confirm if issue still persists here.

    And Thank You!!

  • I have the same, i.e. Drupal : 11.1.5 and csp installed with composer require 'drupal/csp:^2.2', and the error persists.

  • 🇨🇦Canada gapple

    The form is trying to indicate that there is an issue with your policy's reporting configuration
    https://git.drupalcode.org/project/csp/-/blob/2.x/src/Form/CspSettingsFo...

    What are the values in your configuration for csp.settings:enforce.reporting and csp.settings:report-only.reporting?

  • I am facing the same issue.
    I am on Drupal: 11.1.6, CSP: 2.2.2

    The screenshot attached shows my configuration object.

    Under which object would I find the following settings
    csp.settings:enforce.reporting
    csp.settings:report-only.reporting

    Please let me know, if you need more information.
    Thanks

  • I am facing the same issue
    I am on drupal.core: 11.1.6, drupal/csp: 2.2.2

    The screenshot below shows my configuration object.

    Where would I find the said properties?
    csp.settings:enforce.reporting
    csp.settings:report-only.reporting

  • 🇨🇦Canada gapple

    @sudhanshu.b Your configuration looks ridiculously old (like, the format is pre 8.x-1.0), and has not had necessary updates run for over 6 years.
    However, nothing in the module is enabled, so it would be easier to just uninstall and re-install the CSP module to reset it to default configuration.

  • @gapple I tried uninstalling - reinstalling the module version 2.2.2 using drush for the website, as well as using composer. But saw no improvement. The issue still persists.

    My database contains this under csp.settings in hex format.

    {
      "_core": {
        "default_config_hash": "hRfZ8Hy0OO_H_xuVoHK6yrwiNH3bSgtmzUvg46YVHJ0"
      },
      "enforce": false,
      "report": {
        "handler": "csp-module"
      }
    }
    

    I have tried installing CSP version 8.x-1.40, which seems to work as expected and has the following csp.settings:

    {
        "_core": {
            "default_config_hash": "hRfZ8Hy000_H_xuVoHK6yrwiNH3bSgtmzUvg46YVHJ0",
            "enforce": False,
            "report": {
                "handler": "csp-module"
            }
        },
        "report-only": {
            "enable": False,
            "directives": {
                "script-src": {"base": "self"},
                "script-src-attr": {"base": "self"},
                "script-src-elem": {"base": "self"},
                "style-src": {"base": "self"},
                "style-src-attr": {"base": "self"},
                "style-src-elem": {"base": "self"},
                "frame-ancestors": {"base": "self"}
            },
            "reporting": {"plugin": "none"}
        },
        "enforce": {
            "enable": False,
            "directives": {
                "script-src": {"base": "self"},
                "script-src-attr": {"base": "self"},
                "script-src-elem": {"base": "self"},
                "style-src": {"base": "self"},
                "style-src-attr": {"base": "self"},
                "style-src-elem": {"base": "self"},
                "frame-ancestors": {"base": "self"}
            },
            "reporting": {"plugin": "none"}
        }
    }
    

    However, we prefer to use the latest version (^2.0). Could I be missing certain steps when installing CSP? Or it would be because of certain other dependencies?
    Thanks.

  • @gapple, when you wrote "What are the values in your configuration for csp.settings:enforce.reporting and csp.settings:report-only.reporting?" were you referring to settings in the configuration file that should be at https:///admin/config/system/csp? This file is inaccessible because of this issue or is absent.
    Other issues resulting in the above TypeError seem to be resolved by eliminating the offending null value.

  • 🇨🇦Canada gapple

    @sudhanshu.b
    The configurations you posted do not match the module's default installed config for either 2.2.2 [https://git.drupalcode.org/project/csp/-/blob/2.2.2/config/install/csp.s... or 8.x-1.40 [https://git.drupalcode.org/project/csp/-/blob/8.x-1.40/config/install/cs...(e.g. both have the report-only policy enabled by default), so I am not sure what is occurring with your site.

    @johnwt
    You can read the config options directly with drush:
    drush cget csp.settings enforce.reporting
    drush cget csp.settings report-only.reporting

    or through the single item config export in the admin section at /admin/config/development/configuration/single/export

    The values should match those from the install config, if you haven't had CSP installed previously and changed the values.

    I cannot reproduce any issues with the module's configuration on a clean install, or after applying updates to an older configuration.

  • @gapple, thanks for the drush suggestion. This confirms that csp.settings is not being installed. I have tried completely uninstalling and reinstalling the module but the error persists. I get a WSOD when installing the module using extend, dblog mainly reports a lot of non-existent config entity name errors.

  • I have managed to deal with the non-existant config errors and it is working now, so this is fixed as far as I am concerned. Thanks.

Production build 0.71.5 2024