Modernizr Causes Content Security Policy (CSP) Violation Errors

前端 未结 2 1814
一个人的身影
一个人的身影 2020-12-25 11:11

I am attempting to use the new Content Security Policy (CSP) HTTP headers on a test site. When I use CSP in conjunction with Modernizr I get CSP violation e

相关标签:
2条回答
  • 2020-12-25 11:36

    I found a fix without having to use unsafe-inline.

    You can modify the unminimized Modernizr at one line:

    fakeBody = body || document.createElement('body');
    

    convert to

    fakeBody = document.createElement('body');
    

    works on IE9, Firefox, and Chrome.

    0 讨论(0)
  • 2020-12-25 11:41

    I suspect there's no other solution than to rewrite the parts of Modernizr that use inline code or dynamically evaluated code (which applies to both JS and CSS). The experiences of AngularJS ngCsp might be useful here.

    0 讨论(0)
提交回复
热议问题