게시판에 태그와 자바스크립트로 테러를 저질르는 한심하신분들이 종종 있는 관계로


몇일동안 정규표현식과 씨름하다가 만들었습니다.





정해진 태그만 딱 허용하면 테러당할일은 없겠지요..





<%


'//패턴으로 치환할수 있는 eregi_replace()함수를 구현


'//PHP에는 있으나 ASP에는 없기 때문


Function eregi_replace(pattern, replace, text)


Dim eregObj:





Set eregObj = New RegExp:





eregObj.Pattern = pattern: '//패턴 설정


eregObj.IgnoreCase = True: '//대소문자 구분 여부


eregObj.Global = True: '//전체 문서에서 검색





eregi_replace = eregObj.Replace(text, replace): '//Replace String


End Function





'//허용태그 외의 모든 태그제거 함수


Function strip_tags(str,allowtags)


Dim content:


Dim tags:





content = str:


tags = replace(allowtags,",","|"):





content = eregi_replace("<(/?)(?!/|" & tags & ")([^<>]*)?>", "&lt;$1$2&gt;", content):


contents = eregi_replace("(javascript:|vbscript:)+","$1//",contents):


contents = eregi_replace


("(.location|location.|onload=|.cookie|alert(|window.open(|onmouse|onkey|onclick|view-


source:)+","//",contents): '//자바스크립트 실행방지





strip_tags = content:


End Function








'//사용예


Dim permitTags, comment:





permitTags = "br,a,img,table,b,font,div,center,embed":


comment = "<font color=red>허용하지 않은 태그</font>가<br>잘 <b>보이나요?</b><br><script></script>":


comment = comment & "<div align=center>아주 유용할꺼에요~</div><body><html><xmp><pre>":





response.write strip_tags(comment,permitTags):





%>
2009/05/26 13:44 2009/05/26 13:44

Trackback Address :: https://youngsam.net/trackback/503