Skip to content

Commit

Permalink
Backport PR #7578
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
[fix] Tests passing.

* Original sha: 41b0651
* Authored by Nicolás Bevacqua <[email protected]> on 2016-06-29T14:52:19Z

**Commit 2:**
Revert "Revert "Merge pull request #7568 from bevacqua/hotfix/config-xss""

This reverts commit dda84e9.

* Original sha: 4854f2d
* Authored by Nicolás Bevacqua <[email protected]> on 2016-06-29T15:02:17Z
  • Loading branch information
elastic-jasper committed Jun 29, 2016
1 parent 73bb7e4 commit 422f570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/ui/public/metadata.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import $ from 'jquery';
import _ from 'lodash';
// singleton for immutable copy of window.__KBN__

if (!_.has(window, '__KBN__')) {
throw new Error('window.__KBN__ must be set for metadata');
}

const kbn = _.cloneDeep(window.__KBN__ || {});
export default deepFreeze(kbn);
export default deepFreeze(getState());

function deepFreeze(object) {
// for any properties that reference an object, makes sure that object is
Expand All @@ -20,3 +15,12 @@ function deepFreeze(object) {

return Object.freeze(object);
}

function getState() {
const stateKey = '__KBN__';
if (!(stateKey in window)) {
const state = $('kbn-initial-state').attr('data');
window[stateKey] = JSON.parse(state);
}
return window[stateKey];
}
6 changes: 3 additions & 3 deletions src/ui/views/chrome.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- var j = function (o) { return JSON.stringify(o); }
- var appName = 'kibana';
-
var appName = 'kibana';
block vars

Expand All @@ -12,5 +12,5 @@ html(lang='en')
title Kibana
block head
body(kbn-chrome, id='#{appName}-body')
script window.__KBN__ = !{j(kibanaPayload)};
kbn-initial-state(data=JSON.stringify(kibanaPayload))
block content

0 comments on commit 422f570

Please sign in to comment.