๋ฐ์ํ
ํฌ๋ก์ค ์ฌ์ดํธ ์คํฌ๋ฆฝํธ(XSS : cross-site scripting)
๊ฒ์ฆ๋์ง ์์ ์ธ๋ถ ์ ๋ ฅ๊ฐ์ ์๋ต์ ์ผ๋ถ๋ก ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์์ ์ ์์ ์ธ ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋ ์ ์๋ ๋ณด์ ์ฝ์
<%
String errmsg = request.getParameter("errmsg");
%>
....
<td>
<b>Message</b>
</td>
<td>
<%=errmsg%>
</td>
์์ ์ฝ๋์ ๊ฐ์ด request.getParameter("errmsg") ์ ํตํด ๊ฐ์ ธ์จ parameter ๊ฐ์
jsp ํ์ผ์ <%=errmsg%> ๋ก ๋ฐ๋ก ์ฌ์ฉํ๋ ๊ฒฝ์ฐ XSS ๋ณด์ ์ด์๋ฅผ ๋ฐ์์ํฌ ์ ์์ต๋๋ค.
ํด๊ฒฐ๋ฐฉ์
1. XSS ๋ฐฉ์ง ํํฐ ์ฌ์ฉ
<%
String errmsg = request.getParameter("errmsg");
errmsg = errmsg.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>","").replaceAll("\r|\n| ","");
%>
....
<td>
<b>Message</b>
</td>
<td>
<%=errmsg%>
</td>
errmsg = errmsg.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>","").replaceAll("\r|\n| ","");
parameter ์ ๋ณด replaceAllํ๋ ์ฝ๋ ์ถ๊ฐ
2. JSTL <c:out> ํ๊ทธ ์ฌ์ฉ
<%
String errmsg = request.getParameter("errmsg");
%>
....
<td>
<b>Message</b>
</td>
<td>
<c:out value="${errmsg}"/>
</td>
<%=errmsg%> ์ <c:out value="${errmsg}"/> ๋ก ๋ณ๊ฒฝ
์ฐธ๊ณ : https://www.devkuma.com/docs/secure-coding-guide/xss/
๋ฐ์ํ
'Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] Unsupported major.minor version 52.0 Error (1) | 2022.06.10 |
---|---|
[Java] javax.net.ssl.SSLHandshakeException: connection during handshake (0) | 2022.03.23 |
[Java] log4j Log ๋ ๋ฒจ (0) | 2022.01.07 |
[Java] Reflection์ ์ด์ฉํ private ์ ๊ทผํ๊ธฐ (2) | 2021.12.23 |
[Java] jar ํ์ผ ์์ฑํ๊ธฐ (Eclipse / bat ํ์ผ) (1) | 2021.12.16 |
๋๊ธ