Skip to content

웹 컴포넌트 렌더링 경로의 XSS/URL 정제 취약점과 TOC 앵커 충돌 보완 - #178

Open
elecbug with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-potential-bugs
Open

elecbug with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-potential-bugs

Conversation

Copilot AI commented Sep 25, 2026

Copy link
Copy Markdown

문서 렌더링 경로 전반에서 사용자/데이터 기반 속성이 그대로 HTML에 주입되고 있었고, TOC는 헤딩 ID를 단순 인덱스로 덮어써 앵커 충돌과 북마크 호환성 문제가 있었습니다. 이번 변경은 공통 정제 계층을 도입해 렌더링 경로를 일관되게 보호하고, TOC 앵커 생성 방식을 안정적으로 정리합니다.

  • HTML/속성 이스케이프 공통화

    src/scripts/utils/html.ts를 추가해 HTML 텍스트, HTML 속성, 링크 URL, 에셋 URL 정제를 공통 유틸로 분리했습니다.
    button-component, card-component, home-link-card-component, nav-component, contributor-component가 이 유틸을 사용하도록 정리했습니다.

  • 링크 URL과 에셋 URL 처리 분리

    내비게이션/버튼 링크는 SPA에서 의도한 내부 해시 경로와 안전한 스킴만 허용하도록 제한했습니다.
    반면 이미지/아바타는 상대 경로와 http/https를 유지할 수 있도록 별도 정제 경로를 사용해 기존 렌더링을 깨지 않도록 했습니다.

  • 기여자 프로필 링크 정확성 보완

    GitHub 사용자명은 형식 검증을 통과하는 경우에만 직접 프로필 링크를 만들고, 그렇지 않으면 잘못된 다른 계정으로 이동하지 않도록 안전한 기본 링크로 처리합니다.

  • TOC 헤딩 ID 안정화 및 레거시 호환

    헤딩 ID를 단순 숫자 대신 텍스트 기반 slug로 생성해 충돌 가능성을 낮췄습니다.
    기존 숫자 앵커 북마크가 끊기지 않도록 legacy anchor도 함께 삽입해 이전 링크 호환성을 유지합니다.

  • 회귀 테스트 보강

    URL 정제 허용/차단 범위, TOC slug 생성, 기존 ID 보존, legacy anchor 생성 케이스를 테스트에 추가해 변경 동작을 고정했습니다.

예시:

const href = escapeHtmlAttribute(sanitizeUrl(this.getAttribute('href') || '#'));
const imgSrc = escapeHtmlAttribute(sanitizeAssetUrl(imgsrc, ''));
const headingId = heading.id || createUniqueHeadingId(headingText, index, usedIds);

Copilot AI and others added 7 commits September 25, 2026 07:43
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>
Co-authored-by: elecbug <81972855+elecbug@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants