Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AntiXSS in WebAPI?

I'm not clear on how to use the AntiXSS library in my .Net WebAPI 2 project.

I have installed the AntiXSS NuGet package (which gives me v4.3), and have set the encoderType property of httpRuntime in web.config.

Which class should I now use to take advantage of AntiXSS? Does it override the behaviour of System.Web.HttpUtility?

like image 258
Paul Guz Avatar asked Oct 21 '25 13:10

Paul Guz


1 Answers

If using the AntiXSS NuGet package, the correct use is to use Microsoft.Security.Application.Encoder.

According to bdorrans of the MS Web Protection Library (AntiXSS) project, you can indeed use HttpUtility once encoderType is set.

However, it shouldn't normally be a concern to encode output from an API. My scenario is that I'm serving a Single Page Application, and was worried I was injecting unsafe values in to the page via my model. But unless injecting values via .html() or .eval(), any malicious values will not be executed on the client.

like image 188
Paul Guz Avatar answered Oct 23 '25 07:10

Paul Guz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!