Skip to content

Commit 258954a

Browse files
krsy0411claude
andcommitted
[fix] XSS 취약점 방지 - breadcrumb href 속성 이스케이프 처리 추가
Copilot PR 피드백을 반영하여 보안 취약점을 개선했습니다. - escapeHtmlAttribute() 함수 추가: href 속성값을 안전하게 이스케이프 - item.path를 escapedPath로 변환하여 XSS 공격 벡터 차단 - 특수문자(&, <, >, ", ')를 HTML 엔티티로 치환 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 14fd52d commit 258954a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/scripts/breadcrumb.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,32 @@ function escapeHtml(text: string): string {
116116
return div.innerHTML;
117117
}
118118

119+
/**
120+
* href 속성값을 안전하게 escape
121+
* 따옴표, 꺾쇠괄호 등을 HTML 엔티티로 변환
122+
*/
123+
function escapeHtmlAttribute(value: string): string {
124+
return value
125+
.replace(/&/g, '&amp;')
126+
.replace(/"/g, '&quot;')
127+
.replace(/'/g, '&#39;')
128+
.replace(/</g, '&lt;')
129+
.replace(/>/g, '&gt;');
130+
}
131+
119132
/**
120133
* Breadcrumb 아이템을 HTML 문자열로 변환
121134
*/
122135
function renderBreadcrumbItem(item: BreadcrumbItem, isLast: boolean): string {
123136
const escapedName = escapeHtml(item.name);
137+
const escapedPath = escapeHtmlAttribute(item.path);
124138

125139
if (isLast) {
126140
return `<span class="truncate text-gray-400 dark:text-gray-300">${escapedName}</span>`;
127141
}
128142

129143
if (item.linkable) {
130-
return `<a href="${item.path}" class="truncate text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 transition-colors">${escapedName}</a> / `;
144+
return `<a href="${escapedPath}" class="truncate text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 transition-colors">${escapedName}</a> / `;
131145
}
132146

133147
// linkable=false인 항목은 회색으로 표시 (클릭 불가 시각 표시)

0 commit comments

Comments
 (0)