Problem/Motivation
When I use the module with "Use the simplified workspace switcher in the toolbar" enabled and with security rules (Security Kit module in fact), the workspace switcher doesn't work anymore because of an error in the browser console :
Executing inline event handler violates the following Content Security Policy directive 'script-src 'self' (...) . Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present. The action has been blocked.
Steps to reproduce
- Enable WSE
- Enable Use the simplified workspace switcher in the toolbar in Settings.
- Install and enable Security Kit
- Set CSP rules
- Create a new worskpace and switch to it.
- Click on the workspace button in the admin toolbar and click on "Live" workspace
- Error occurs in the console.
Proposed resolution
The simplified toolbar switcher renders a
element with an inlinem onchange="this.form.submit();" attribute. Inline event handlers cannot be whitelisted via CSP hashes (per spec), and are blocked by strict CSP policies
such as those enforced by the Seckit module.
To fix it, a possible solution could be:
- Replace the inline onchange attribute with a data-wse-workspace-switcher attribute used as a JS hook.
- Attach a new JS file that submits the form through the data-wse-workspace-switcher attribute.
- Attach the new wse/simplified_toolbar_switcher library to the form.
- Declare the new library in wse.libraries.yml, pointing to the existing js/wse-simplified-toolbar-switcher.js file.
| Comment | File | Size | Author |
|---|---|---|---|
| wse_simplified_toolbar_switcher.png | 14.23 KB | aurianahg |
Issue fork wse-3577029
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #7
amateescu commentedMade a couple of changes to the MR: moved the new code to the existing
wse.toolbar.jsfile because we don't really need a new library for this.Merged into 3.0.x and back-ported to 2.0.x, thanks!