Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

의미없는 블로그

[ASP.NET/C#] XSS 필터링 (HttpUtility.HtmlEncode / RemoveHtmlTag / RemoveScriptTag) 본문

# 나/source Code

[ASP.NET/C#] XSS 필터링 (HttpUtility.HtmlEncode / RemoveHtmlTag / RemoveScriptTag)

SaltLee 2024. 4. 23. 11:20

HttpUtility.HtmlEncode 로 입력값 필터링 

< > " 이런거 필터링 됨

( ) 는 안됨

 

Index.aspx.cs

Request["ReturnUrl"] 로 입력값 받고

HttpUtility.UrlEncode(ReturnUrl) 로 필터링 걸음

Index.aspx

위에서 받은 ReturnUrl 출력하고 있음

/Index.aspx?ReturnUrl=

스크립트 넣어보면 URL 인코딩 돼서 출력됨

 

RemoveHtmlTag, RemoveScriptTag 로 입력값 필터링

이건 정규표현식으로 구현해서 쓰는건가 보다

 

MySellerInfo.aspx.cs

[WebMethod] SetSellerMinishopInfo 는 /MySellerInfo.aspx/SetSellerMinishopInfo 요렇게 쓴다는 뜻임 

파라미터에 RemoveHtmlTag(RemoveScriptTag(파라미터)) 걸고 있음

RemoveScriptTag 는 <script, <noscript, script> 요런것들 필터링 함

RemoveHtmlTag 는 <aaa>, </bbb> 요런것들 필터링 함

MySellerInfo.aspx

위에서 필터링 걸었던 파라미터들에 해당하는 값 출력하고 있음

/MySellerInfo.aspx/SetSellerMinishopInfo 

<script> <aaa> 이런 형태들 다 필터링 됨

일단 < 로 열리면 > 로 닫힐때까지는 무조건 필터링 됨

그래서 <aaa<sss>>> 넣으면 >> 만 남음

Comments