Skip to content

Commit

Permalink
Inject CSP config via HTML tag rather than inline JavaScript (#31514)
Browse files Browse the repository at this point in the history
This allows us to support a more flexible set of CSP rules that do not
necessarily rely on nonce.
  • Loading branch information
epixa authored Feb 20, 2019
1 parent 11da27b commit 8aada89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/legacy/ui/ui_render/bootstrap/template.js.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
var kbnCsp = JSON.parse(document.querySelector('kbn-csp').getAttribute('data'));
window.__kbnStrictCsp__ = kbnCsp.strictCsp;
window.__kbnNonce__ = kbnCsp.nonce;

if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) {
var legacyBrowserError = document.getElementById('kbn_legacy_browser_error');
legacyBrowserError.style.display = 'flex';
Expand Down
1 change: 1 addition & 0 deletions src/legacy/ui/ui_render/views/chrome.pug
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,6 @@ html(lang=locale)
block head

body
kbn-csp(data=JSON.stringify({ nonce, strictCsp }))
kbn-injected-metadata(data=JSON.stringify(injectedMetadata))
block content
3 changes: 0 additions & 3 deletions src/legacy/ui/ui_render/views/ui_app.pug
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,4 @@ block content
// intentional as we check for the existence of __kbnCspNotEnforced__ in
// bootstrap.
window.__kbnCspNotEnforced__ = true;
script(nonce=nonce).
window.__kbnStrictCsp__ = !{strictCsp};
window.__kbnNonce__ = '!{nonce}';
script(src=bootstrapScriptUrl, nonce=nonce)

0 comments on commit 8aada89

Please sign in to comment.