Skip to content

Commit e4568cd

Browse files
committed
Fix XSS vulnerability in flat/nested view toggle
1 parent 5d9ef53 commit e4568cd

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

gcovr-templates/html/gcovr.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@
10731073
return;
10741074
}
10751075

1076-
var originalContent = null; // stash for restoring nested view
1076+
var originalNodes = null; // stash for restoring nested view
10771077

10781078
function collectFlatFiles(nodes, parentPath) {
10791079
var results = [];
@@ -1205,9 +1205,12 @@
12051205
function switchToFlat() {
12061206
if (!window.GCOVR_TREE_DATA) return;
12071207

1208-
// Stash original content
1209-
if (originalContent === null) {
1210-
originalContent = fileList.innerHTML;
1208+
// Stash original DOM nodes
1209+
if (originalNodes === null) {
1210+
originalNodes = document.createDocumentFragment();
1211+
while (fileList.firstChild) {
1212+
originalNodes.appendChild(fileList.firstChild);
1213+
}
12111214
}
12121215

12131216
var flatFiles = collectFlatFiles(window.GCOVR_TREE_DATA, '');
@@ -1219,7 +1222,9 @@
12191222
return aVal - bVal;
12201223
});
12211224

1222-
fileList.innerHTML = '';
1225+
while (fileList.firstChild) {
1226+
fileList.removeChild(fileList.firstChild);
1227+
}
12231228
for (var i = 0; i < flatFiles.length; i++) {
12241229
fileList.appendChild(buildFlatRow(flatFiles[i]));
12251230
}
@@ -1230,8 +1235,12 @@
12301235
}
12311236

12321237
function switchToNested() {
1233-
if (originalContent !== null) {
1234-
fileList.innerHTML = originalContent;
1238+
if (originalNodes !== null) {
1239+
while (fileList.firstChild) {
1240+
fileList.removeChild(fileList.firstChild);
1241+
}
1242+
fileList.appendChild(originalNodes);
1243+
originalNodes = null;
12351244
}
12361245
if (appContainer) appContainer.classList.remove('flat-mode');
12371246
document.documentElement.classList.remove('early-flat-mode');

0 commit comments

Comments
 (0)