diff options
Diffstat (limited to 'core/misc/drupalSettingsLoader.js')
-rw-r--r-- | core/misc/drupalSettingsLoader.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/core/misc/drupalSettingsLoader.js b/core/misc/drupalSettingsLoader.js index 73cf91dae1ea..6cc4be9f41e0 100644 --- a/core/misc/drupalSettingsLoader.js +++ b/core/misc/drupalSettingsLoader.js @@ -1,15 +1,24 @@ /** -* DO NOT EDIT THIS FILE. -* See the following change record for more information, -* https://www.drupal.org/node/2815083 -* @preserve -**/ + * @file + * Parse inline JSON and initialize the drupalSettings global object. + */ (function () { - const settingsElement = document.querySelector('head > script[type="application/json"][data-drupal-selector="drupal-settings-json"], body > script[type="application/json"][data-drupal-selector="drupal-settings-json"]'); + // Use direct child elements to harden against XSS exploits when CSP is on. + const settingsElement = document.querySelector( + 'head > script[type="application/json"][data-drupal-selector="drupal-settings-json"], body > script[type="application/json"][data-drupal-selector="drupal-settings-json"]', + ); + + /** + * Variable generated by Drupal with all the configuration created from PHP. + * + * @global + * + * @type {object} + */ window.drupalSettings = {}; if (settingsElement !== null) { window.drupalSettings = JSON.parse(settingsElement.textContent); } -})();
\ No newline at end of file +})(); |