| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- XSS 차단
- column명비교
- WEB-INF 노출
- CSS
- @tistory.com
- 네이버 지도API
- 스팸글 차단
- apache tomcat 연동 보안
- Java
- 자동 로봇 글등록
- html5
- 배경이 가려진 레이어 팝업
- 자바스크립트
- 비밀번호 유효성
- 스크롤 이동
- MARGIN
- PADDING
- 클라우드
- 암호화&복호화
- 중복필드
- addbatch
- 일괄처리
- 다음메일
- fckeditor
- 고창
- 퀵메뉴
- 치환
- 청보리밭
- 2012 사진공모전
- POST 전송
Archives
- Today
- Total
그곰의 생활
XSS 차단 java 선언 본문
/*
* XSS 방지
*/
public static String removeXSS(String str, boolean use_html) {
String str_low = "";
if(use_html){ // HTML tag를 사용하게 할 경우 부분 허용
// HTML tag를 모두 제거
str = str.replaceAll("<","<");
str = str.replaceAll(">",">");
// 특수 문자 제거
str = str.replaceAll("\"",">");
str = str.replaceAll("&", "&");
str = str.replaceAll("%00", null);
str = str.replaceAll("\"", """);
str = str.replaceAll("\'", "'");
str = str.replaceAll("%", "%");
str = str.replaceAll("../", "");
str = str.replaceAll("..\\\\", "");
str = str.replaceAll("./", "");
str = str.replaceAll("%2F", "");
// 허용할 HTML tag만 변경
str = str.replaceAll("<p>", "<p>");
str = str.replaceAll("<P>", "<P>");
str = str.replaceAll("<br>", "<br>");
str = str.replaceAll("<BR>", "<BR>");
// 스크립트 문자열 필터링 (선별함 - 필요한 경우 보안가이드에 첨부된 구문 추가)
str_low= str.toLowerCase();
if( str_low.contains("javascript") || str_low.contains("script") || str_low.contains("iframe") ||
str_low.contains("document") || str_low.contains("vbscript") || str_low.contains("applet") ||
str_low.contains("embed") || str_low.contains("object") || str_low.contains("frame") ||
str_low.contains("grameset") || str_low.contains("layer") || str_low.contains("bgsound") ||
str_low.contains("alert") || str_low.contains("onblur") || str_low.contains("onchange") ||
str_low.contains("onclick") || str_low.contains("ondblclick") || str_low.contains("enerror") ||
str_low.contains("onfocus") || str_low.contains("onload") || str_low.contains("onmouse") ||
str_low.contains("onscroll") || str_low.contains("onsubmit") || str_low.contains("onunload"))
{
str = str_low;
str = str.replaceAll("javascript", "x-javascript");
str = str.replaceAll("script", "x-script");
str = str.replaceAll("iframe", "x-iframe");
str = str.replaceAll("document", "x-document");
str = str.replaceAll("vbscript", "x-vbscript");
str = str.replaceAll("applet", "x-applet");
str = str.replaceAll("embed", "x-embed");
str = str.replaceAll("object", "x-object");
str = str.replaceAll("frame", "x-frame");
str = str.replaceAll("grameset", "x-grameset");
str = str.replaceAll("layer", "x-layer");
str = str.replaceAll("bgsound", "x-bgsound");
str = str.replaceAll("alert", "x-alert");
str = str.replaceAll("onblur", "x-onblur");
str = str.replaceAll("onchange", "x-onchange");
str = str.replaceAll("onclick", "x-onclick");
str = str.replaceAll("ondblclick","x-ondblclick");
str = str.replaceAll("enerror", "x-enerror");
str = str.replaceAll("onfocus", "x-onfocus");
str = str.replaceAll("onload", "x-onload");
str = str.replaceAll("onmouse", "x-onmouse");
str = str.replaceAll("onscroll", "x-onscroll");
str = str.replaceAll("onsubmit", "x-onsubmit");
str = str.replaceAll("onunload", "x-onunload");
}
}else{ // HTML tag를 사용하지 못하게 할 경우
str = str.replaceAll("\"",">");
str = str.replaceAll("&", "&");
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll("%00", null);
str = str.replaceAll("\"", """);
str = str.replaceAll("\'", "'");
str = str.replaceAll("%", "%");
str = str.replaceAll("../", "");
str = str.replaceAll("..\\\\", "");
str = str.replaceAll("./", "");
str = str.replaceAll("%2F", "");
}
return str;
}
또는 네이버 개발센터에 Lucy XSS 라이브러리를 이용하여 처리
http://dev.naver.com/projects/lucy-xss/
'Server-side > Lang' 카테고리의 다른 글
| [스크랩]JSP 스팸글 차단 - 조그마한거 (0) | 2011.11.17 |
|---|---|
| [스크랩]JSP 자동등록 방지 (0) | 2011.11.17 |
| fckeditor 2.6 자바 버전 upload 설정 (0) | 2011.07.21 |
| 문자열 치환 (0) | 2011.06.30 |
| 일괄처리 addBatch() 함수 (0) | 2011.06.30 |
Comments
Lucy_XSS.zip