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

  1. Enable WSE
  2. Enable Use the simplified workspace switcher in the toolbar in Settings.
  3. Install and enable Security Kit
  4. Set CSP rules
  5. Create a new worskpace and switch to it.
  6. Click on the workspace button in the admin toolbar and click on "Live" workspace
  7. 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.

CommentFileSizeAuthor
wse_simplified_toolbar_switcher.png14.23 KBaurianahg

Issue fork wse-3577029

Command icon 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

aurianahg created an issue. See original summary.

aurianahg changed the visibility of the branch 3577029-csp-violation-caused to hidden.

amateescu made their first commit to this issue’s fork.

amateescu’s picture

Version: 3.0.0-alpha1 » 3.0.x-dev
Status: Active » Fixed

Made a couple of changes to the MR: moved the new code to the existing wse.toolbar.js file because we don't really need a new library for this.

Merged into 3.0.x and back-ported to 2.0.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.