Skip to content

Update rendering template to avoid potential XSS attack #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 15 additions & 11 deletions libs/jsonTree/jsonTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,25 @@ var jsonTree = (function() {
var self = this,
el = document.createElement('li'),
labelEl,
wrapper = document.createElement('div'),
template = function(label, val) {
var str = '\
wrapper.innerHTML = '\
<span class="jsontree_label-wrapper">\
<span class="jsontree_label">"' +
label +
'"</span> : \
<span class="jsontree_label"></span> : \
</span>\
<span class="jsontree_value-wrapper">\
<span class="jsontree_value jsontree_value_' + self.type + '">' +
val +
'</span>' +
(!isLast ? ',' : '') +
'</span>';

return str;
<span class="jsontree_value jsontree_value_' + self.type + '"></span>\
' + (!isLast ? ',' : '') + '\
</span>';

var labelNode = wrapper.querySelector('.jsontree_label');
var valueNode = wrapper.querySelector('.jsontree_value');

// Escape HTML characters in the label and value to prevent XSS attacks
labelNode.textContent = '"' + label + '"';
valueNode.textContent = val;

return wrapper.innerHTML;
};

self.label = label;
Expand Down