0

Possible Duplicate:
How do you avoid XSS vulnerabilities in ASP.Net (MVC)?

Hi I need to create a guest book, where users can add their comments and have theme being displayed without moderation on a page.

I'm using Asp.Net MVC 3 in C#.

  • Could you point me out some tecnics? thanks

Thanks for your time.

PS I'm using Razor

Community
  • 1
  • 1
GibboK
  • 71,848
  • 143
  • 435
  • 658

2 Answers2

3

Just make sure all user generated content is HTML encoded before you write it to the browser and you'll be fine. Razor view engine does this by default... it's actually quite hard to screw up on this using Razor.

So:

@"<script>badness</script>"

in Razor would render in HTML as

&lt;script&gt;badness%lt;/script&gt;

to achieve the same in ASP.NET view engine use <%:expression%> as opposed to <%=expression%>

<%:"<script>badness</script>"%>
spender
  • 117,338
  • 33
  • 229
  • 351