Skip to content

Commit a424744

Browse files
authored
Merge pull request #638 from github/copilot/sub-pr-637
fix(website): escape backslashes in file paths to prevent string context breakout
2 parents 611474f + 9e44173 commit a424744

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 the JavaScript string literal in the onclick attribute
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)