Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline styles and Content Security Policy #2423

Closed
penartur opened this issue Sep 17, 2015 · 2 comments · Fixed by #2723
Closed

Inline styles and Content Security Policy #2423

penartur opened this issue Sep 17, 2015 · 2 comments · Fixed by #2723

Comments

@penartur
Copy link

As of now, Chosen for JQuery does not work correctly when inline styles usage is forbidden by an appropriate Content-Security-Policy.
The problem is that, when it creates the "chosen" menu in set_up_html, it uses "style" param to specify width:

'style': "width: #{this.container_width()};"

JQuery supports specifying the width directly (not by CSS properties): http://api.jquery.com/width/ ; this one should solve the problem.

Unfortunately, writing front-end JS compatible across different browsers (and testing it) is not my strong side, so I'll only create this issue, and will not supply any pull request with it.

@stof
Copy link
Collaborator

stof commented Sep 17, 2015

@penartur jQuery.width sets inline styles too.

@okdana
Copy link

okdana commented Oct 8, 2016

Bumping. This is still an issue — Chosen does not like CSP very much.

Here's an example of the kind of errors you get with style-src: 'self' (using Chrome here because its console output is more explicit, but the same problem occurs in Firefox or where-ever):

screen shot 2016-10-07 at 19 46 02

This is what causes that particular error:

div = $('<div />', {
    'style': style_block
});

However, there are issues in other places, too, like here (the line OP linked) and here.

I am not a super expert front-end dev either, but as far as i understand it, this is caused by writing directly to an element's style attribute. Modifying individual properties on an HTMLElement's style property, on the other hand, should not run afoul of these restrictions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants