javascript - Content Security Policy multiple nonce - Stack Overflow

I have a single page application (built incore MVC 2.2), where html section are loaded on the fly. On

I have a single page application (built in core MVC 2.2), where html section are loaded on the fly.

On main document, added CSP policy with a dynamically generated header looks like:

Content-Security-Policy: script-src 'self' 'nonce-I64vb811BxRNGV9Xf0pM'

Then es a page section loaded via jquery ajax load function. page section contains a script (from src) with a nonce. Page section served with CSP header looks like

Content-Security-Policy: script-src 'self' 'nonce-ci5TQsyidT8x2jwBLRHS'

all good but browsers (chrome, safari blocking the script), with message:

jqueryscriptsbundle.js:formatted:43 Refused to execute inline script 
because it violates the following 
Content Security Policy directive: "script-src 'self' 'nonce-I64vb811BxRNGV9Xf0pM'

So browser is paring nonce of script i.e. ci5TQsyidT8x2jwBLRHS with root/main page nonce value I64vb811BxRNGV9Xf0pM hence script blocked.

Is it correct behavior ? What can I do to make it work?

I have a single page application (built in core MVC 2.2), where html section are loaded on the fly.

On main document, added CSP policy with a dynamically generated header looks like:

Content-Security-Policy: script-src 'self' 'nonce-I64vb811BxRNGV9Xf0pM'

Then es a page section loaded via jquery ajax load function. page section contains a script (from src) with a nonce. Page section served with CSP header looks like

Content-Security-Policy: script-src 'self' 'nonce-ci5TQsyidT8x2jwBLRHS'

all good but browsers (chrome, safari blocking the script), with message:

jqueryscriptsbundle.js:formatted:43 Refused to execute inline script 
because it violates the following 
Content Security Policy directive: "script-src 'self' 'nonce-I64vb811BxRNGV9Xf0pM'

So browser is paring nonce of script i.e. ci5TQsyidT8x2jwBLRHS with root/main page nonce value I64vb811BxRNGV9Xf0pM hence script blocked.

Is it correct behavior ? What can I do to make it work?

Share Improve this question asked Jan 14, 2020 at 10:12 SSASSA 5,4834 gold badges38 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Your initial CSP, loaded with the page, provides a nonce. What you're trying to do is add another nonce, via Ajax, after the initial page load. CSP explicitly doesn't allow this; that's not a bug -- it's the entire point.

What you might do is allow a script-src of strict-dynamic. This allows you to authorize a script, and anything loaded by that script is also authorized. See https://developer.mozilla/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744047745a4549495.html

相关推荐

  • javascript - Content Security Policy multiple nonce - Stack Overflow

    I have a single page application (built incore MVC 2.2), where html section are loaded on the fly. On

    10天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信