Sanitize HTML before storing in the DB or before rendering? (AntiXSS library in ASP.NET)

后端 未结 4 1327
广开言路
广开言路 2020-12-29 11:59

I have an editor that lets users add HTML that is stored in the database and rendered on a web page. Since this is untrusted input, I plan to use Microsoft.Security.Ap

4条回答
  •  既然无缘
    2020-12-29 12:38

    You can use the in the page directive the parameter ValidateRequest="true". In this way all the Request data is validated and if there's a validation problem you can always catch the error. It also prevents sql injection threads and others not only possible XSS.

    With numeric data, you can validate integer overflow or misuse of data types with Int32.TryParse() or any other of the TryParse family (Byte.TryParse Int16.TryParse...)

    No need to use any other class or additional sanitizer method.

提交回复
热议问题