Skip to content

Commit af7ec09

Browse files
authored
Merge pull request #173 from rajbos/alert-autofix-25
Potential fix for code scanning alert no. 25: Client-side cross-site scripting
2 parents 7735255 + 87eec5b commit af7ec09

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/webview/diagnostics/main.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,16 @@ function renderLayout(data: DiagnosticsData): void {
926926
const sorted = [...message.sessionFolders].sort((a: any, b: any) => b.count - a.count);
927927

928928
// Build the session folders table using DOM APIs to avoid HTML injection
929-
const container = document.createElement('div');
930-
container.className = 'session-folders-table';
929+
let container = reportTabContent.querySelector('.session-folders-table') as HTMLElement | null;
930+
if (!container) {
931+
container = document.createElement('div');
932+
container.className = 'session-folders-table';
933+
} else {
934+
// Clear existing content so we can rebuild safely
935+
while (container.firstChild) {
936+
container.removeChild(container.firstChild);
937+
}
938+
}
931939

932940
const heading = document.createElement('h4');
933941
heading.textContent = 'Main Session Folders (by editor root):';
@@ -983,12 +991,12 @@ function renderLayout(data: DiagnosticsData): void {
983991

984992
// Open link cell
985993
const openCell = document.createElement('td');
986-
const link = document.createElement('a');
987-
link.href = '#';
988-
link.className = 'reveal-link';
989-
link.setAttribute('data-path', encodeURIComponent(sf.dir));
990-
link.textContent = 'Open directory';
991-
openCell.appendChild(link);
994+
const openLink = document.createElement('a');
995+
openLink.href = '#';
996+
openLink.className = 'reveal-link';
997+
openLink.setAttribute('data-path', encodeURIComponent(sf.dir));
998+
openLink.textContent = 'Open directory';
999+
openCell.appendChild(openLink);
9921000
row.appendChild(openCell);
9931001

9941002
tbody.appendChild(row);
@@ -997,19 +1005,17 @@ function renderLayout(data: DiagnosticsData): void {
9971005
// Find where to insert or replace the session folders table
9981006
// It should be inserted after the report-content div but before the button-group
9991007
const existingTable = reportTabContent.querySelector('.session-folders-table');
1000-
if (existingTable && existingTable.parentNode) {
1001-
existingTable.parentNode.replaceChild(container, existingTable);
1002-
} else {
1008+
if (!existingTable) {
10031009
// Insert after the report-content div
10041010
const reportContent = reportTabContent.querySelector('.report-content');
1005-
if (reportContent && reportContent.parentNode) {
1006-
if (reportContent.nextSibling) {
1007-
reportContent.parentNode.insertBefore(container, reportContent.nextSibling);
1008-
} else {
1009-
reportContent.parentNode.appendChild(container);
1010-
}
1011+
if (reportContent) {
1012+
reportContent.insertAdjacentElement('afterend', container);
1013+
} else {
1014+
// Fallback: append to the tab content if report-content is missing
1015+
reportTabContent.appendChild(container);
10111016
}
10121017
}
1018+
10131019
setupStorageLinkHandlers();
10141020
}
10151021
}

0 commit comments

Comments
 (0)