Skip to content

Commit 22e0203

Browse files
authored
Merge pull request #175 from rajbos/alert-autofix-22
Potential fix for code scanning alert no. 22: Client-side cross-site scripting
2 parents 0efdff7 + 038525a commit 22e0203

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/webview/diagnostics/main.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ function getEditorStats(files: SessionFileDetails[]): { [key: string]: { count:
209209
return stats;
210210
}
211211

212+
function safeText(value: unknown): string {
213+
if (value === null || value === undefined) {
214+
return '';
215+
}
216+
if (typeof value === 'string') {
217+
// Use existing HTML escaping to avoid XSS when inserting into innerHTML.
218+
return escapeHtml(value);
219+
}
220+
return String(value);
221+
}
222+
212223
function renderSessionTable(detailedFiles: SessionFileDetails[], isLoading: boolean = false): string {
213224
if (isLoading) {
214225
return `
@@ -234,7 +245,7 @@ function renderSessionTable(detailedFiles: SessionFileDetails[], isLoading: bool
234245
: detailedFiles;
235246

236247
// Summary stats for filtered files
237-
const totalInteractions = filteredFiles.reduce((sum, sf) => sum + sf.interactions, 0);
248+
const totalInteractions = filteredFiles.reduce((sum, sf) => sum + Number(sf.interactions || 0), 0);
238249
const totalContextRefs = filteredFiles.reduce((sum, sf) => sum + getTotalContextRefs(sf.contextReferences), 0);
239250

240251
// Sort filtered files

0 commit comments

Comments
 (0)