Skip to content
This repository has been archived by the owner on Sep 10, 2020. It is now read-only.

Avoid any XSS issue while displaying the package description in the search results #65

Merged
merged 1 commit into from
Aug 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@
'<li><i class="fa fa-code-fork"></i> ' + hit.github.forks + '</li>' +
'</ul>';
}

// extract & escape the description to prevent any XSS issue keeping the highlighting tags
var description = hit._highlightResult.description && hit._highlightResult.description.value;
description = $('<div />').text(description).html().replace(/&lt;(\/?)em&gt;/g, '<$1em>');

var row = '<tr id="' + hit.objectID + '">' +
'<td>' +
'<p><a itemprop="name" href="/libraries/'+ hit.name + '">' +
hit._highlightResult.name.value +
'</a></p>' +
'<p class="text-muted">' + (hit._highlightResult.description && hit._highlightResult.description.value) + '</p>' +
'<p class="text-muted">' + description + '</p>' +
'<ul class="list-inline">' +
$.map(hit._highlightResult.keywords || [], function(e) {
var extraClass = (e.matchLevel !== 'none') ? 'highlight' : '';
Expand Down