Skip to content

Commit 2cbcede

Browse files
committed
xss fix
1 parent 0a36834 commit 2cbcede

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unibox",
3-
"version": "1.14.1",
3+
"version": "1.14.2",
44
"main": [
55
"js/unibox.min.js",
66
"css/unibox.min.css"

css/unibox.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ img.unibox-vis {
7676
margin-left: 8px;
7777
margin-top: 6px;
7878
font-size: 18px;
79+
text-align: left;
80+
margin-bottom: 8px;
7981
}
8082

8183
.unibox-ivf {

css/unibox.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/unibox.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ var UniBox = function () {
9090
// the maximum width of the suggest box, default: as wide as the input box
9191
var maxWidth = undefined;
9292

93+
var entityMap = {
94+
"&": "&",
95+
"<": "&lt;",
96+
">": "&gt;",
97+
'"': '&quot;',
98+
"'": '&#39;',
99+
"/": '&#x2F;'
100+
};
101+
93102
// hide the search suggests
94103
function resetSuggests(event) {
95104

@@ -179,6 +188,12 @@ var UniBox = function () {
179188
return key.replace(/[ "§$%&/(){}+*,.;|]/g, '_').toLowerCase();
180189
}
181190

191+
function escapeHtml(string) {
192+
return String(string).replace(/[&<>"'\/]/g, function (s) {
193+
return entityMap[s];
194+
});
195+
}
196+
182197
// update suggest box when new data is given
183198
function updateSuggestBox(data) {
184199

@@ -189,6 +204,7 @@ var UniBox = function () {
189204
}
190205

191206
var searchString = searchBox.val();
207+
var searchStringXss = escapeHtml(searchString);
192208

193209
//// fill the box
194210
suggestBox.html('');
@@ -240,10 +256,10 @@ var UniBox = function () {
240256

241257
if (suggest['link'] != undefined) {
242258
suggestLine += '<a href="' + suggest['link'] + '">';
243-
suggestLine += highlightSearchWords(suggest['name'], searchString);
259+
suggestLine += highlightSearchWords(suggest['name'], searchStringXss);
244260
suggestLine += '</a>';
245261
} else {
246-
suggestLine += '<span>' + highlightSearchWords(suggest['name'], searchString) + '</span>';
262+
suggestLine += '<span>' + highlightSearchWords(suggest['name'], searchStringXss) + '</span>';
247263
}
248264

249265
if (extraHtml != undefined) {
@@ -326,7 +342,7 @@ var UniBox = function () {
326342
}
327343

328344
var invisibleBox = searchBoxParent.find('#unibox-invisible');
329-
invisibleBox.html(searchString.replace(new RegExp(word['name'], 'gi'), '<span>' + word['name'] + '</span>'));
345+
invisibleBox.html(searchStringXss.replace(new RegExp(word['name'], 'gi'), '<span>' + word['name'] + '</span>'));
330346

331347
//console.log(word['image']+' : '+jQuery.inArray(word['image'], ivfWords));
332348

js/unibox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unibox.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"search",
77
"suggestion"
88
],
9-
"version": "1.14.1",
9+
"version": "1.14.2",
1010
"author": {
1111
"name": "David Urbansky",
1212
"url": "https://github.com/ddsky/unibox"

0 commit comments

Comments
 (0)