flawopen.com/크로스 사이트 스크립팅/Java

크로스 사이트 스크립팅 in Java

높음 CWE-79 Draft — pending review
Language: English Português (Brasil) Español Français Deutsch Русский 简体中文 日本語 हिन्दी 한국어 Bahasa Indonesia
쉬운 설명 (ELI5)

Imagine a bulletin board where someone posts an instruction that forces the viewer's computer to secretly send their session cookie to an attacker.

이 페이지의 주요 용어
output encoding
Converting special markup characters into safe entities so browsers display them as text rather than script.

발생 원인

XSS in Java web applications occurs when JSP, Thymeleaf, or FreeMarker templates render request parameters directly into response streams without encoding.

실제 피해 사례

In 2005, the Samy XSS worm infected over 1 million user profiles on MySpace in under 20 hours, forcing the platform offline.

Documented historical AppSec case study.

취약한 코드 vs 수정된 코드

VULNERABLE

Welcome, <%= request.getParameter("name") %>
FIXED

Welcome,

수정 방법이 동작하는 이유

JSTL and Thymeleaf th:text convert sensitive HTML characters (<, >, &, ") into inert HTML entities.

언어별 주요 주의사항

Thymeleaf th:utext

th:utext explicitly disables escaping. Use th:text for untrusted data.

흔한 오해

"Spring Boot automatically prevents all XSS"

Spring handles URL and JSON encoding, but template rendering depends on proper tag usage.

취약점 확인 방법

grep -rn "<%=.*getParameter" --include="*.jsp" . grep -rn "th:utext" --include="*.html" .
Scan JSP and template views using FindSecBugs (rule XSS_REQUEST_PARAMETER_TO_JSP_WRITER).

예방 체크리스트

자주 묻는 질문 (FAQ)

How should rich user HTML be handled in Java?

Use OWASP Java HTML Sanitizer to strip dangerous tags and attributes before rendering.

참고 자료

언어 선택: Java Python JavaScript Java Go PHP C# Rust
참고할 취약점: SQL Injection Command InjectionPath Traversal