Skip to content

Commit 5a20ac1

Browse files
committed
fix display of highlight, which can leak html. (why doesn't ES scrub this, since it injects html itself???) [UFI-14]
1 parent 075236e commit 5a20ac1

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

dist.tgz

876 Bytes
Binary file not shown.

src/plugin/iframe_root/modules/components/narrative/data.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
define(['bluebird', 'moment', 'knockout', '../../lib/searchApi'], function (Promise, moment, ko, SearchAPI) {
1+
define([
2+
'bluebird',
3+
'moment',
4+
'knockout',
5+
'../../lib/searchApi',
6+
'../../lib/security'],
7+
(Promise, moment, ko, SearchAPI, security) => {
28
'use strict';
39

410
// For now, this fakes the search...
@@ -51,7 +57,7 @@ define(['bluebird', 'moment', 'knockout', '../../lib/searchApi'], function (Prom
5157
label: label,
5258
highlights: obj.highlight[field].map(function (highlight) {
5359
return {
54-
highlight: highlight
60+
highlight: security.scrubHighlight(highlight)
5561
};
5662
})
5763
});

src/plugin/iframe_root/modules/components/reference/data.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
define([
22
'bluebird',
33
'knockout',
4+
'uuid',
45
'../../lib/searchApi',
6+
'../../lib/security',
57
'yaml!../../data/stopWords.yml'
68
], function (
79
Promise,
810
ko,
11+
Uuid,
912
SearchAPI,
13+
security,
1014
stopWordsDb
1115
) {
1216
'use strict';
@@ -68,14 +72,15 @@ define([
6872
console.warn('highlight field ' + field + ' not found in type spec', obj);
6973
}
7074

75+
7176
matches
7277
.push({
7378
id: field,
7479
label: label,
7580
highlights: obj.highlight[field]
7681
.map((highlight) => {
7782
return {
78-
highlight
83+
highlight: security.scrubHighlight(highlight)
7984
};
8085
})
8186
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
define(['uuid'], (Uuid) => {
2+
'use strict';
3+
4+
function encodeHTML(possibleHTML) {
5+
const node = document.createElement('div');
6+
node.innerHTML = possibleHTML;
7+
return node.innerText;
8+
}
9+
function scrubHighlight(highlight) {
10+
const emStart = new Uuid(4).format();
11+
const emFinish = new Uuid(4).format();
12+
13+
const safe1 = highlight.replace('<em>', emStart).replace('</em>', emFinish);
14+
const safe2 = encodeHTML(safe1);
15+
return safe2.replace(emStart, '<em>').replace(emFinish, '</em>');
16+
}
17+
18+
return {encodeHTML, scrubHighlight};
19+
});

0 commit comments

Comments
 (0)