2019年6月25日 星期二

[研究] [ASP.NET] Cross-Site Scripting(XSS) 防範,白名單輸入驗證

[研究] [ASP.NET] Cross-Site Scripting(XSS) 防範,白名單輸入驗證

2019-06-25

使用Regular Expression (正規表示式) 僅允許白名單
中文 [\u4e00-\u9fa5]
英文 [z-zA-Z]
數字 [0-9]
混合 [\u4e00-\u9fa5_a-zA-Z0-9_]+$
加上長度  [\u4e00-\u9fa5_a-zA-Z0-9_]{12,100}

允許HTML 語法輸入的地方使用HtmlSanitizer白名單過濾,參考https://github.com/Vereyon/HtmlRuleSanitizer

首頁 › 轉碼互通 › 碼表查詢 › UTF-8
http://www.cns11643.gov.tw/AIDB/codetable_search.do

******************************

Visual Studio 2017 v15.2,RegularExpressionValidator 有一些常用的規則運算式。




網際網路 URL
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

電子郵件
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

(完)

相關

[研究] Microsoft Anti-XSS Library V4.3 (Anti-Cross Site Scripting Library)
https://shaurong.blogspot.com/2017/06/microsoft-anti-xss-library-v43-anti.html

[研究][ASP.NET] 用了 AntiXssEncoder.HtmlEncoder 仍被 Fortify SCA v17.20 說有問題
https://shaurong.blogspot.com/2018/04/aspnet-antixssencoderhtmlencoder.html

[研究] [ASP.NET] DropDownList1 的 Cross-site scripting (XSS) (Reflected XSS) 修正
https://shaurong.blogspot.com/2017/09/aspnet-dropdownlist1-cross-site.html

[研究] [ASP.NET] Cross-Site Scripting(XSS) 防範,白名單輸入驗證
https://shaurong.blogspot.com/2019/06/aspnet-cross-site-scriptingxss.html

[研究] X-XSS Protection
https://shaurong.blogspot.com/2017/06/x-xss-protection.html

沒有留言:

張貼留言