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

Content-Security-Policy style-src violation #459

Open
IncredibleHat opened this issue Jun 11, 2020 · 0 comments
Open

Content-Security-Policy style-src violation #459

IncredibleHat opened this issue Jun 11, 2020 · 0 comments

Comments

@IncredibleHat
Copy link

Noticed a small flaw in the way the lSPager is built in the script, which causes a violation with any Content-Security-Policy that does not allow unsafe-inline (which anyone implementing CSP should not allow).

You have a pagers build loop of:

pagers += '<li style="width:100%;' + property + ':' + thumbWidth + 'px;' + gutter + ':' + settings.thumbMargin + 'px"><a href="#"><img src="' + thumb + '" /></a></li>';

By explicitly setting a style attribute in this manner, it will cause CSP to block it (and thus really break the layout of the lightslider pagers). I made a simple fix to the script by changing that line above to:

pagers += '<li class="lSsetCSS"><a href="#"><img src="' + thumb + '" /></a></li>';

And then after: $cSouter.find('.lSPager').html(pagers); I added this line:

$cSouter.find(".lSsetCSS").css('width','100%').css(property,thumbWidth +'px').css(gutter,settings.thumbMargin +'px');

What this does is properly set the css styles for each of those elements via the CSSOM, instead of inject style attributes which get parsed and subsequently blocked by the CSP. Hopefully this helps anyone else who runs into this issue, as it seems this lightslider library is no longer updated.

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

No branches or pull requests

1 participant