Skip to content

Commit fb5f22a

Browse files
Copilotaaronpowell
andcommitted
fix(website): properly escape backslashes and quotes in file paths
The previous implementation only escaped single quotes, which could allow backslashes in file paths to break out of the JavaScript string context. Now we escape backslashes first (\ -> \\), then single quotes (' -> \'), preventing potential security issues. Fixes CodeQL alert #26 for incomplete string escaping. Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
1 parent 8b9fa46 commit fb5f22a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

website/src/scripts/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ export function setupDropdownCloseHandlers(): void {
298298
export function getActionButtonsHtml(filePath: string, small = false): string {
299299
const btnClass = small ? 'btn-small' : '';
300300
const iconSize = small ? 14 : 16;
301-
const escapedPath = filePath.replace(/'/g, "\\'");
301+
// Escape backslashes first, then single quotes to prevent breaking out of string context
302+
const escapedPath = filePath.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
302303

303304
return `
304305
<button class="btn btn-secondary ${btnClass} action-download" data-path="${escapeHtml(filePath)}" onclick="event.stopPropagation(); window.__downloadFile && window.__downloadFile('${escapedPath}')" title="Download file">

0 commit comments

Comments
 (0)