javascript - Microsoft Edge not accepting hashes for Content-Security Policy -


the problem

content-security-policy should blacklist script , style parsing default , allow based on various instructions of 1 verified hash of expected output. browser must fail implement javascript or css has not been given matching hash in advance. code matching hash should executed normal. microsoft edge refusing js/css in-page blocks.

demonstration original source code

<!doctype html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="content-security-policy" content="default-src 'self'; style-src 'sha256-jtuhvm7uqo2kx5iegwxn+rheyzzsyfelfo2gxvyeuwa='; script-src https://ajax.googleapis.com 'sha256-izzrsbzugxfoatdnb/e6rqbssyxqrp7w8ytzd2wg/rc=';" /> <meta http-equiv="x-content-security-policy" content="default-src 'self'; style-src 'sha256-jtuhvm7uqo2kx5iegwxn+rheyzzsyfelfo2gxvyeuwa='; script-src https://ajax.googleapis.com 'sha256-izzrsbzugxfoatdnb/e6rqbssyxqrp7w8ytzd2wg/rc=';" /> <style>#loading{color:transparent}#loading:after{color:green;content:"style loaded."}</style> </head> <body> <span id="loading">hashes loading...</span> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script>alert("script loaded.")</script> 
  • expected behaviour: body should change "style loaded.", alert box should "script loaded.", external javascript should not throw error. console shows no issues.
  • actual behaviour: body stuck on "hashes loading...". hashes refused, external javascript accepted. console shows errors:

csp14304: unknown source ‘'sha256-jtuhvm7uqo2kx5iegwxn+rheyzzsyfelfo2gxvyeuwa='’ directive ‘style-src’ in - source ignored.

csp14306: no sources given directive ‘style-src’ - equivalent using ‘none’ , prevent downloading of resources of type.

csp14304: unknown source ‘'sha256-izzrsbzugxfoatdnb/e6rqbssyxqrp7w8ytzd2wg/rc='’ directive ‘script-src’ in - source ignored.

csp14312: resource violated directive ‘style-src 'sha256-jtuhvm7uqo2kx5iegwxn+rheyzzsyfelfo2gxvyeuwa='’ in : inline style. resource blocked.

csp14312: resource violated directive ‘script-src link-removed-insufficient-reputation-on-stackoverflow-should-be-the-google-api-url 'sha256-izzrsbzugxfoatdnb/e6rqbssyxqrp7w8ytzd2wg/rc='’ in : inline script. resource blocked.

attempted fixes

  • verifying hashes correct: double-checked calculation binary, that's it. not do, other browsers accepting them.
  • changed values of default-src , connect-src self rather none

i can't think of else try.

update 24 hours later: added x-content-security-policy completeness & jsbin url updated, though doesn't make difference particular situation.

edit: may incorrect. see comments above.

ie 11 not support content-security-policy (only x-content-security-policy), fails open. ie 12 supports csp, not grok nonces/hashes, fails closed... unless supply 'unsafe-inline' in content-security-policy header.

csp level 2 says "if hash or nonce supplied, ignore 'unsafe-inline'." backwards compatibility since older browsers grok 'unsafe-inline' not nonces/hashes. see http://www.w3.org/tr/csp2/#directive-script-src


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -