Recent Posts
Recent Comments
Link
06-30 12:53
Today
Total
관리 메뉴

삶 가운데 남긴 기록 AACII.TISTORY.COM

JAVA 보안 Cross-site Scripting 본문

DEV&OPS/Java

JAVA 보안 Cross-site Scripting

ALEPH.GEM 2022. 8. 3. 17:53

Cross-site Scripting

악의적인 스크립트로 정보 유츨등 공격을 할 수 있습니다.

사용자 입력 문자열에서 <, >, &, "," 등을 &lt, &gt, &amp, &quot로 치환해 방어합니다.

HTML 태그를 허용하는 게시판에서는 허용하는 태그(white list)를 선정 한 후 허용된 태그만 허용하는 방식을 사용합니다.

보안 검증이 되어 있는 API를 사용해야 합니다.

 

아래 예제는 name 이라는 입력 값에 스크립트 (예: 를 수행하게 하여 쿠키 정보 유출 등 피해를 줄 수 있게 됩니다.

<%
    String name = request.getParameter("name");
%>
<p>NAME:<%=name%></p>

replaceAll() 메소드로 위험한 문자를 교체합니다.

<%
    String name = request.getParameter("name");
    if(name != null){
        name = name.replaceAll("<", "&lt;");
        ...
    }
%>

OSWASP(http://Https://www.owasp.org/index.php/Esapi)에서 제공하는 보안 API를 사용합니다.

J2EE, Javascript 라이브러리를 제공합니다.

String eid = request.getParameter("eid");
String safeEid = ESAPI.encoder().encodeForHTML.Attribute(eid);

아래 예제는 http://josephoconnell.com/java/xss-html-filter/ 에서 제공하는 XSS Filter를 이용한 입력값 필터링 예제입니다.

 

import com.josephoconnell.html.HTMLInputFilter;
...
private String filter(String input){
    String clean = new HTMLInputFilter().filter(input);
    return clean;
}
...

 

 

참고

http://cwe.mitre.org/data/definitions/79.html 

 

CWE - CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (4.8)

div.collapseblock { display:inline} CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')Weakness ID: 79Abstraction: BaseStructure: Simple The software does not neutralize or incorrectly neutralizes user-controllable

cwe.mitre.org

 

http://cwe.mitre.org/top25/ 

 

https://cwe.mitre.org/top25/

 

cwe.mitre.org

 

 

 

728x90

'DEV&OPS > Java' 카테고리의 다른 글

JAVA 보안 Unrestricted Upload of File with Dangerous Type  (0) 2022.08.04
JAVA 보안 OS Command Injection  (0) 2022.08.03
JAVA 보안 Resource Injection  (0) 2022.08.03
JAVA 보안 SQL Injection  (0) 2022.08.03
CRUD  (0) 2022.07.26