-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecure-code.java
23 lines (20 loc) ยท 1.1 KB
/
secure-code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<% String keyword = request.getParameter("keyword"); %>
// ๋ฐฉ๋ฒ1. ์
๋ ฅ๊ฐ์ ๋ํ์ฌ ์คํฌ๋ฆฝํธ ๊ณต๊ฒฉ๊ฐ๋ฅ์ฑ์ด ์๋ ๋ฌธ์์ด์ ์นํํ๋ค.
keyword = keyword.replaceAll("&", "&");
keyword = keyword.replaceAll("<", "<");
keyword = keyword.replaceAll(">", ">");
keyword = keyword.replaceAll("๏ฟฆ"", """);
keyword = keyword.replaceAll("'", "'");
keyword = keyword.replaceAll("/"", "/");
keyword = keyword.replaceAll("(", "(");
keyword = keyword.replaceAll(")", ")");
// ๊ฒ์์ด : <%=keyword%>
//๋ฐฉ๋ฒ2. JSP์์ ์ถ๋ ฅ๊ฐ์ JSTL c:out ์ ์ฌ์ฉํ์ฌ ์ฒ๋ฆฌํ๋ค.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
// ๊ฒ์๊ฒฐ๊ณผ : <c:out value="${m.content}"/>
//๋ฐฉ๋ฒ3. ์ ๋ง๋ค์ด์ง ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉ(NAVER Lucy-XSS-Filter, OWASP ESAPI, OWASP Java-Encoder-Project)
<script type="text/javascript">
document.write("keyword:" +
<%=Encoder.encodeForJS(Encoder.encodeForHTML(keyword))%>);
</script>