-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
csp: optional strict mode to block insecure browsers
A content security policy is a great addition to the protections built into Kibana, but it's not effective in older browsers (like IE11) that do not enforce the policy. When CSP strict mode is enabled, right before the Kibana app is bootstrapped, a basic safety check is performed to see if "naked" inline scripts are rejected. If inline scripting is allowed by the browser, then an error message is presented to the user and Kibana never attempts to bootstrap.
- Loading branch information
Showing
5 changed files
with
86 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,67 @@ | ||
window.onload = function () { | ||
var files = [ | ||
'{{dllBundlePath}}/vendors.bundle.dll.js', | ||
'{{regularBundlePath}}/commons.bundle.js', | ||
'{{regularBundlePath}}/{{appId}}.bundle.js' | ||
]; | ||
|
||
var failure = function () { | ||
// make subsequent calls to failure() noop | ||
failure = function () {}; | ||
|
||
var err = document.createElement('h1'); | ||
err.style['color'] = 'white'; | ||
err.style['font-family'] = 'monospace'; | ||
err.style['text-align'] = 'center'; | ||
err.style['background'] = '#F44336'; | ||
err.style['padding'] = '25px'; | ||
err.innerText = document.querySelector('[data-error-message]').dataset.errorMessage; | ||
|
||
document.body.innerHTML = err.outerHTML; | ||
} | ||
|
||
function loadStyleSheet(path) { | ||
var dom = document.createElement('link'); | ||
|
||
dom.addEventListener('error', failure); | ||
dom.setAttribute('rel', 'stylesheet'); | ||
dom.setAttribute('href', path); | ||
document.head.appendChild(dom); | ||
} | ||
|
||
function createJavascriptElement(path) { | ||
var dom = document.createElement('script'); | ||
|
||
dom.setAttribute('async', ''); | ||
dom.addEventListener('error', failure); | ||
dom.setAttribute('src', file); | ||
dom.addEventListener('load', next); | ||
document.head.appendChild(dom); | ||
} | ||
|
||
{{#each styleSheetPaths}} | ||
loadStyleSheet('{{this}}'); | ||
{{/each}} | ||
|
||
(function next() { | ||
var file = files.shift(); | ||
if (!file) return; | ||
|
||
var dom = document.createElement('script'); | ||
|
||
dom.setAttribute('async', ''); | ||
dom.setAttribute('nonce', window.__webpack_nonce__); | ||
dom.addEventListener('error', failure); | ||
dom.setAttribute('src', file); | ||
dom.addEventListener('load', next); | ||
document.head.appendChild(dom); | ||
}()); | ||
}; | ||
if (window.__kbnStrictCsp && window.__kbnCspNotEnforced__) { | ||
var legacyBrowserError = document.getElementById('kbn_legacy_browser_error'); | ||
legacyBrowserError.style = 'display: flex;' | ||
} else { | ||
var loadingMessage = document.getElementById('kbn_loading_message'); | ||
loadingMessage.style = 'display: flex;' | ||
|
||
window.onload = function () { | ||
var files = [ | ||
'{{dllBundlePath}}/vendors.bundle.dll.js', | ||
'{{regularBundlePath}}/commons.bundle.js', | ||
'{{regularBundlePath}}/{{appId}}.bundle.js' | ||
]; | ||
|
||
var failure = function () { | ||
// make subsequent calls to failure() noop | ||
failure = function () {}; | ||
|
||
var err = document.createElement('h1'); | ||
err.style['color'] = 'white'; | ||
err.style['font-family'] = 'monospace'; | ||
err.style['text-align'] = 'center'; | ||
err.style['background'] = '#F44336'; | ||
err.style['padding'] = '25px'; | ||
err.innerText = document.querySelector('[data-error-message]').dataset.errorMessage; | ||
|
||
document.body.innerHTML = err.outerHTML; | ||
} | ||
|
||
function loadStyleSheet(path) { | ||
var dom = document.createElement('link'); | ||
|
||
dom.addEventListener('error', failure); | ||
dom.setAttribute('rel', 'stylesheet'); | ||
dom.setAttribute('href', path); | ||
document.head.appendChild(dom); | ||
} | ||
|
||
function createJavascriptElement(path) { | ||
var dom = document.createElement('script'); | ||
|
||
dom.setAttribute('async', ''); | ||
dom.addEventListener('error', failure); | ||
dom.setAttribute('src', file); | ||
dom.addEventListener('load', next); | ||
document.head.appendChild(dom); | ||
} | ||
|
||
{{#each styleSheetPaths}} | ||
loadStyleSheet('{{this}}'); | ||
{{/each}} | ||
|
||
(function next() { | ||
var file = files.shift(); | ||
if (!file) return; | ||
|
||
var dom = document.createElement('script'); | ||
|
||
dom.setAttribute('async', ''); | ||
dom.setAttribute('nonce', window.__webpack_nonce__); | ||
dom.addEventListener('error', failure); | ||
dom.setAttribute('src', file); | ||
dom.addEventListener('load', next); | ||
document.head.appendChild(dom); | ||
}()); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters