ASP: XSS방지를 위한 htmlspecialchars 함수

XSS방지를 위해 PHP에서는 htmlspecialchars함수를 사용하면 된다. ASP에서는 기본적으로 이런 기능의 함수가 없어서 같은 기능을 하는 함수를 만들었다. 사용자 입력 내용이 HTML로 출력될 때는 XSS방지를 위해서 반드시 htmlspecialchars함수를 써야 한다.

<form method="post" action="test.asp">  
<input type="text" name="test" value="<%=htmlspecialchars(Request("test"))%>">  
<input type="submit">  
</form>

<%  
Function htmlspecialchars(sStr)  
    htmlspecialchars = Replace( sStr, "&", "&" )  
    htmlspecialchars = Replace( htmlspecialchars, ">", ">" )  
    htmlspecialchars = Replace( htmlspecialchars, "<", "<" )  
    htmlspecialchars = Replace( htmlspecialchars, """", "&quot;" )  
    htmlspecialchars = Replace( htmlspecialchars, "'", "&#039;" )  
End Function  
%>