Reputation: 3354
I'm using HttpUtility.HtmlEncode
to sanitise user input to prevent against XSS attacks. My problem is that HtmlEncode
converts special characters like ü
into their Html equivalent code. I can't find the documentation about what it does and doesn't encode. Then in order to display this correctly back to the user I need to HtmlDecode
it.
2 questions:
How does HtmlEncode
decide that it needs to encode a supposedly valid character like ü
and not other unicode characters like standard English alphabet characters. Does HtmlEncode
encode all non ascii characters? What is the best way to prevent script tags but allow special characters like umlauts without creating a special ignore list?
Does using HtmlDecode
expose a risk as it is converting back potentially malicious javascript
Upvotes: 2
Views: 5474
Reputation: 3555
There is FAR more to be told about encoding and decoding than I can write in here, and people before me have explained it far more exhaustive than I can. This article on preventing XSS in Asp.Net can explain you what XSS is and how you can prevent it.
Upvotes: 1