Skip to content

Improve security, accessibility, performance, and test coverage#4

Open
seonghobae wants to merge 23 commits into
yencarnacion:masterfrom
ContextualWisdomLab:master
Open

Improve security, accessibility, performance, and test coverage#4
seonghobae wants to merge 23 commits into
yencarnacion:masterfrom
ContextualWisdomLab:master

Conversation

@seonghobae

@seonghobae seonghobae commented Jul 7, 2026

Copy link
Copy Markdown

Overview

This PR improves html4tree so generated directory indexes are safer, more accessible, easier to validate, and more robust for real-world filenames.

What changed

  • Hardened traversal against symlink-based path traversal by using NOFOLLOW_LINKS checks for the top directory and child directory traversal.
  • Prevented index.html symlink overwrite issues by writing to a temporary file and then replacing the generated index atomically.
  • Escaped directory and file names before inserting them into generated HTML to reduce XSS risk.
  • Reworked escapeHtml() from chained replace() calls to a single-pass, lazily allocated StringBuilder implementation to reduce intermediate string allocations.
  • URL-encoded generated href paths so spaces, slashes, and non-ASCII filenames are handled more reliably.
  • Improved .html4ignore handling by compiling valid regex patterns once, ignoring empty lines, and skipping invalid regexes without aborting the whole directory render.
  • Improved generated HTML accessibility and UX with lang, charset, viewport, main, nav, aria-label, empty-directory feedback, and focus/hover styles.
  • Added Kotlin/JUnit tests and JaCoCo verification for traversal behavior, ignore-file handling, HTML escaping, URL encoding, max-depth behavior, and symlink protections.

CodeGraph review

I used colbymchenry/codegraph to index the current code and confirm the main impact paths:

  • go() -> process_dir() -> process_ignore_file()
  • process_dir() -> escapeHtml() / urlEncodePath() / write_index_file()
  • Regression coverage is concentrated in MainTest.kt and UtilTest.kt.

Validation

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./gradlew test

Result: BUILD SUCCESSFUL

Related fork PRs

The ContextualWisdomLab fork first merged the currently valid, mergeable improvements that had already passed review and required checks:

seonghobae and others added 23 commits June 21, 2026 15:36
…vement-17389468144540365696

🎨 Palette: [모바일 대응 및 접근성 개선] 생성되는 HTML의 UX 향상
Merged after central .github required workflows completed and OpenCode approved the current head.
Merged after resolving conflicts, addressing Strix findings, passing Gradle tests, and receiving central OpenCode approval.
Merged after resolving conflicts with current accessibility structure, passing Gradle tests, and receiving central OpenCode approval.
Merged after updating against current master, passing Gradle tests, and receiving central OpenCode approval.
Merged after combining symlink traversal protections with current safe-write behavior, passing Gradle tests, and receiving central OpenCode approval.
Merged after resolving conflicts with current master, preserving prior symlink traversal protections and adding the maxLevel enqueue guard from PR #28.

Verified with JDK 11 Gradle tests and required current-head OpenCode approval.
Merged after refreshing against current master and combining decorative-icon aria-hidden spans with the existing semantic landmark, aria-label, and symlink-safe generator changes.

Verified with JDK 11 Gradle tests and required current-head OpenCode approval.
Merged after refreshing against current master and preserving the existing accessibility, performance, and symlink protections. Adds a CSP meta tag for generated HTML as defense-in-depth.

Verified with JDK 11 Gradle tests and required current-head OpenCode approval.
Merged after resolving conflicts with current master and removing a brittle internal coverage test. Adds a helpful empty-directory message to generated listings.

Verified with JDK 11 Gradle tests and required current-head OpenCode approval.
canonicalFile로 인해 심볼릭 링크 제한 검사가 무력화되는 문제를 absoluteFile.toPath().normalize().toFile()로 교체하여 정상화했습니다.

Co-authored-by: seonghobae <8172694+seonghobae@users.noreply.github.com>
* ⚡ Bolt: escapeHtml 성능 최적화 (단일 루프 및 StringBuilder 사용)

* ⚡ Bolt: escapeHtml 성능 최적화 (단일 루프 및 StringBuilder 사용)

기존의 연쇄적인 `.replace()` 호출은 각 치환 단계마다 새로운 중간 문자열을 메모리에 할당하여 쓰레기 수집(Garbage Collection) 및 CPU 부하를 발생시키는 주요 성능 병목이었습니다. 단일 루프 방식은 한 번의 순회만으로 치환을 수행하며, 문자열 수정이 필요할 때만 `StringBuilder`를 초기화하여 메모리 할당을 최소화합니다.

---------

Co-authored-by: seonghobae <8172694+seonghobae@users.noreply.github.com>
@seonghobae seonghobae changed the title 보안, 접근성, 성능 및 테스트 커버리지 개선 Improve security, accessibility, performance, and test coverage Jul 7, 2026
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