The inline CSS and JS output violate standard CSP policies (not allowing unsafe-inline)
And Drupal coding best practices (no inline javascript, keep design separate from the content)
Can the JS and CSS come from libraries instead?

Comments

jimconte created an issue. See original summary.

gapple’s picture

Title: CSS and JS violate SecKit CSP, Make Libraries » Compatibility with Content Security Policy
Version: 8.x-1.2 » 8.x-1.x-dev
Issue tags: -csp, -Security +Content Security Policy
svenryen’s picture

Good point. There's room for some refactoring once all the bug reports have been settled. Thanks for the focus on this.

anybody’s picture

@gapple: Thank you very much! You're absolutely right! As an expert creating wonderful modules like "ga" - could you perhaps help a bit here with a first implementation or some hints how or where to start?

I guess that would help a lot!

gapple’s picture

It looks like there is one place where inline JS and CSS is added to the page: https://git.drupalcode.org/project/eu-cookie-compliance/-/blob/8.x-1.x/e.... I'm unsure why this is done with inline script.

It looks like it should maybe either be converted to load a library and use hook_library_info_alter to update the the files that are included in the library based on the relevant configuration, or it should pass the necessary info via drupalSettings (as is done elsewhere).

svenryen’s picture

We won't be doing inline css in 2.x.

svenryen’s picture

Title: Compatibility with Content Security Policy » [2.x] Compatibility with Content Security Policy

I'm flagging this for 2.x, with possibility for backport to 1.x.

caco_d25’s picture

Version: 8.x-1.x-dev » 8.x-1.14
Assigned: Unassigned » caco_d25
Status: Active » Needs review
StatusFileSize
new8.84 KB

This patch create and attach JS file instead of using inline JS

svenryen’s picture

Thanks for the patch, @caco_d25.

Do we have to do something similar for css?

gapple’s picture

Will take a better look at the patch later, but with the snippet being written out to a file I don't see any reason to keep using $variables['#attached']['html_head'][] instead of defining a library and using $variables['#attached']['library'][].

The library will most likely need {preprocess: false} on the file to ensure it's not aggregated.

svenryen’s picture

Assigned: caco_d25 » svenryen
svenryen’s picture

I brushed up the patch a bit and fixed some coding style issues. Here's a revised patch.

svenryen’s picture

Assigned: neslee canil pinto » Unassigned
svenryen’s picture

It seems that my patch in #12 is for a different issue, possibly #3208780: Allow config settings to be saved independent of related modules, and got saved with the wrong file name.

I'll take a look at the patch from #8 tomorrow.

svenryen’s picture

StatusFileSize
new5.35 KB

Here's an updated patch.

The EventSubscriber was mistakenly committed in #3236506: Fix PHP Coding Standards for EUCC.

  • svenryen committed bb9f855 on 8.x-1.x
    Issue #3029549 by svenryen, caco_d25, gapple, jimconte, Anybody:...
svenryen’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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